Split tree-based calculation into iteration and exit paths