Update algorithm from master.