Added an iterative solution.