WIP rework to use non-recursive approach