Make some code more readable by removing recursion