fix crash on shutdown