Fixes to shut down clean