Index: /trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskBuilder.java
===================================================================
--- /trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskBuilder.java	(revision 1361)
+++ /trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskBuilder.java	(revision 1362)
@@ -192,10 +192,10 @@
         if (!(instance instanceof SelectionInstance)) {
             throw new IllegalArgumentException
-                ("illegal type of sequence instance provided: " + instance.getClass());
+                ("illegal type of selection instance provided: " + instance.getClass());
         }
 
         if (!(child instanceof TaskInstance)) {
-            throw new IllegalArgumentException
-                ("illegal type of task instance provided: " + child.getClass());
+            throw new IllegalArgumentException("illegal type of task instance provided: " +
+                                               (child == null ? null : child.getClass()));
         }
         
@@ -353,6 +353,14 @@
                 ("illegal type of task instance provided: " + taskInstance.getClass());
         }
-        
+        if (!(task instanceof Task)) {
+            throw new IllegalArgumentException("illegal type of task provided: " + task.getClass());
+        }
+        
+        if (((TaskInstance) taskInstance).getTask() instanceof Task) {
+            ((Task) ((TaskInstance) taskInstance).getTask()).removeInstance(taskInstance);
+        }
         ((TaskInstance) taskInstance).setTask(task);
+        
+        ((Task) task).addInstance(taskInstance);
     }
 
