Fixed race condition with Shutdown flag