Added endgame case (untested)