Shutdown handler fixes