Fix restarting and shutting down