finally fix crash on exit bug (it's about time!)