adding shutdown logic