Better use STL algorithms in Endgame functions