Integrated the three algorithms