fixed a crash on possible app exit