Added end-of-game logic