the second algorithm

a small change