Update algorithm2