the start of algorithm 2