Fix detecting end of the game