fix app crash on exit