algorithm 1 done