Adding a check for the end of the game