update algorithm 1