Fixed shutdown and cleanup sequence