Finished writing 2nd algorithm.