Fix iterative algorithm.