Update algorithm

fixed bug