fix crash on exit