Added the iterative version