Fix for a crash during shutdown