detects end of game and restarts