update algorithm 1 with Output code etc.