added invariant check that n->child->parent == n