fix shutdown logic