fixed app crash when put in background
merge refactoring and crash fix