Iterative version