Added endgame logic.