Finished the algorithms