added end game logic