update algorithm 2