Made the computations iterative instead of recursive.