made a small change to the algorithm