added end of game logic