addede flattenTagged to keep terminal tags, fixed flatten to updateChildPointers