completed the algorithm for the paper.