set_name now occurs before set_parent.

Also check for existence of name before setting reference in the parent node.