fixed a crash on exit