Index: branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/GrammarModifier.cs
===================================================================
--- branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/GrammarModifier.cs	(revision 5686)
+++ branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/GrammarModifier.cs	(revision 5792)
@@ -26,4 +26,6 @@
   public static class GrammarModifier {
     internal static void AddInvokeSymbol(ISymbolicExpressionTreeGrammar grammar, string functionName, int nArgs, CutPoint startCutPoint, IEnumerable<CutPoint> argumentCutPoints) {
+      if (!grammar.ContainsSymbol(startCutPoint.Child.Symbol)) return;
+
       var invokeSym = new InvokeFunction(functionName);
       grammar.AddSymbol(invokeSym);
@@ -31,31 +33,20 @@
 
       //allow invoke symbol everywhere, where the child of the startCutPoint was allowed
-      foreach (ISymbol parent in grammar.Symbols) {
-        if (grammar.IsAllowedChildSymbol(parent, startCutPoint.Child.Symbol))
-          grammar.AddAllowedChildSymbol(parent, invokeSym);
-        else {
-          for (int i = 0; i < grammar.GetMaximumSubtreeCount(parent); i++) {
-            if (grammar.IsAllowedChildSymbol(parent, startCutPoint.Child.Symbol, i))
-              grammar.AddAllowedChildSymbol(parent, invokeSym, i);
-          }
-        }
-      }
+      SetAllowedParentSymbols(grammar, startCutPoint.Child.Symbol, invokeSym);
 
       if (nArgs > 0) {
         //set allowed child symbols of invoke symbol 
         foreach (ISymbol child in grammar.Symbols) {
-          if (argumentCutPoints.All(x => grammar.IsAllowedChildSymbol(x.Parent.Symbol, child)))
-            grammar.AddAllowedChildSymbol(invokeSym, child);
-          else {
-            int i = 0;
-            foreach (CutPoint argumentCutPoint in argumentCutPoints) {
-              if (grammar.IsAllowedChildSymbol(argumentCutPoint.Parent.Symbol, child, argumentCutPoint.ChildIndex))
-                grammar.AddAllowedChildSymbol(invokeSym, child, i);
-              i++;
-            }
+          int i = 0;
+          foreach (CutPoint argumentCutPoint in argumentCutPoints) {
+            if (grammar.IsAllowedChildSymbol(argumentCutPoint.Parent.Symbol, child, argumentCutPoint.ChildIndex))
+              grammar.AddAllowedChildSymbol(invokeSym, child, i);
+            i++;
           }
         }
       }
     }
+
+
 
     internal static void AddArgumentSymbol(ISymbolicExpressionTreeGrammar originalGrammar, ISymbolicExpressionTreeGrammar grammar, IEnumerable<int> argumentIndexes, IEnumerable<CutPoint> argumentCutPoints) {
@@ -65,13 +56,28 @@
         grammar.SetSubtreeCount(argSymbol, 0, 0);
 
-        foreach (ISymbol parent in originalGrammar.Symbols) {
-          if (parent is StartSymbol || parent is ProgramRootSymbol) continue;
-          if (originalGrammar.IsAllowedChildSymbol(parent, pair.CutPoint.Child.Symbol))
-            grammar.AddAllowedChildSymbol(parent, argSymbol);
+        foreach (var symb in grammar.Symbols) {
+          if (symb is ProgramRootSymbol || symb is StartSymbol) continue;
+          if (originalGrammar.IsAllowedChildSymbol(symb, pair.CutPoint.Child.Symbol))
+            grammar.AddAllowedChildSymbol(symb, argSymbol);
           else {
-            for (int i = 0; i < originalGrammar.GetMaximumSubtreeCount(parent); i++) {
-              if (originalGrammar.IsAllowedChildSymbol(parent, pair.CutPoint.Child.Symbol, i))
-                grammar.AddAllowedChildSymbol(parent, argSymbol, i);
+            for (int i = 0; i < grammar.GetMaximumSubtreeCount(symb); i++) {
+              if (originalGrammar.IsAllowedChildSymbol(symb, pair.CutPoint.Child.Symbol, i))
+                grammar.AddAllowedChildSymbol(symb, argSymbol, i);
             }
+          }
+        }
+      }
+    }
+
+    internal static void SetAllowedParentSymbols(ISymbolicExpressionTreeGrammar grammar, ISymbol symbol, ISymbol newSymbol) {
+      foreach (var symb in grammar.Symbols) {
+        if (symb is ProgramRootSymbol) continue;
+        if (newSymbol is Argument && symb is StartSymbol) continue;
+        if (grammar.IsAllowedChildSymbol(symb, symbol))
+          grammar.AddAllowedChildSymbol(symb, newSymbol);
+        else {
+          for (int i = 0; i < grammar.GetMaximumSubtreeCount(symb); i++) {
+            if (grammar.IsAllowedChildSymbol(symb, symbol, i))
+              grammar.AddAllowedChildSymbol(symb, newSymbol, i);
           }
         }
