Fix bug where the game would freeze when changing states