Fix algorithm 1.