fix end of game logic