FIX: Crash on shutting down in some cases