Update algorithm

Running but results are not correct.