Added a previousState variable to be able to go back to the correct state when entering the pauseState