adding endgame logic