fixed crashes on swith app on/off