fixed app sometimes crashing on exit