refactored recursion. working on config