Refactored recursion, tests are passing now