Fix circular reference detection in hierarchical mode.