onPause fix

Fixes crashes on application close