Finished part of the algorithm.