reusing code, another recursion eliminated