Fixes to shutdown