Fixed recursion, and data structure. looks to actually work as expected