diff --git a/undo.py b/undo.py
index d53ce81da79765994a1725ca795d529cf9c09754_dW5kby5weQ==..2611bcb4f5e49851e833011a14a0482c3d934c4e_dW5kby5weQ== 100644
--- a/undo.py
+++ b/undo.py
@@ -153,5 +153,6 @@
                 self.gd_parent.where = self.node_parent
             else:
                 self.gd_parent.children[self.parent_index] = self.node_parent
+                self.node_parent.parent = self.gd_parent
         elif isinstance(self.node_parent, Select):
             self.node_parent.where = self.node
@@ -156,5 +157,6 @@
         elif isinstance(self.node_parent, Select):
             self.node_parent.where = self.node
+            self.node.parent = self.node_parent
         else:
             self.node_parent.insert(self.index, self.node)
         # register reference from the removed node
@@ -244,6 +246,7 @@
 
     def undo(self, selection):
         """undo the operation on the union's children"""
+        self.select.parent = self.union
         self.union.children.remove(self.select)
         
 class RemoveSelectOperation(AppendSelectOperation):
@@ -254,7 +257,7 @@
 
     def undo(self, selection):
         """undo the operation on the union's children"""
-        self.union.children.insert(self.origindex, self.select)
+        self.union.insert(self.origindex, self.select)
 
 __all__ = ('SelectionManager', 'MakeVarOperation', 'UndefineVarOperation',
            'SelectVarOperation', 'UnselectVarOperation', 'AddNodeOperation',