Algorithm

Updated the algorithm