hierarchy recursion logic