Code for optional recursion through parents