Fix for hang on shutdown