Modified the onPause method