Add iterative solution.
Refactor the code.