fix to crash on exit