Completed initial implementation of the algorithm.