Finished everything related to the previous algorithm