Fix to shutdown code