Rewrite FixNesting implementation to be tree-based.