Index: branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Grammars/SymbolicExpressionGrammarBase.cs
===================================================================
--- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Grammars/SymbolicExpressionGrammarBase.cs	(revision 12155)
+++ branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Grammars/SymbolicExpressionGrammarBase.cs	(revision 12891)
@@ -41,5 +41,5 @@
     private IEnumerable<ISymbol> StorableSymbols {
       get { return symbols.Values.ToArray(); }
-      set { symbols = value.ToDictionary(sym => sym.Name); }
+      set { foreach (var s in value) symbols.Add(s.Name, s); }
     }
 
@@ -47,5 +47,5 @@
     private IEnumerable<KeyValuePair<ISymbol, Tuple<int, int>>> StorableSymbolSubtreeCount {
       get { return symbolSubtreeCount.Select(x => new KeyValuePair<ISymbol, Tuple<int, int>>(GetSymbol(x.Key), x.Value)).ToArray(); }
-      set { symbolSubtreeCount = value.ToDictionary(x => x.Key.Name, x => x.Value); }
+      set { foreach (var pair in value) symbolSubtreeCount.Add(pair.Key.Name, pair.Value); }
     }
 
@@ -53,19 +53,22 @@
     private IEnumerable<KeyValuePair<ISymbol, IEnumerable<ISymbol>>> StorableAllowedChildSymbols {
       get { return allowedChildSymbols.Select(x => new KeyValuePair<ISymbol, IEnumerable<ISymbol>>(GetSymbol(x.Key), x.Value.Select(GetSymbol).ToArray())).ToArray(); }
-      set { allowedChildSymbols = value.ToDictionary(x => x.Key.Name, x => x.Value.Select(y => y.Name).ToList()); }
+      set { foreach (var pair in value) allowedChildSymbols.Add(pair.Key.Name, pair.Value.Select(y => y.Name).ToList()); }
     }
 
     [Storable(Name = "AllowedChildSymbolsPerIndex")]
     private IEnumerable<KeyValuePair<Tuple<ISymbol, int>, IEnumerable<ISymbol>>> StorableAllowedChildSymbolsPerIndex {
-      get { return allowedChildSymbolsPerIndex.Select(x => new KeyValuePair<Tuple<ISymbol, int>, IEnumerable<ISymbol>>(Tuple.Create<ISymbol, int>(GetSymbol(x.Key.Item1), x.Key.Item2), x.Value.Select(y => GetSymbol(y)).ToArray())).ToArray(); }
-      set { allowedChildSymbolsPerIndex = value.ToDictionary(x => Tuple.Create(x.Key.Item1.Name, x.Key.Item2), x => x.Value.Select(y => y.Name).ToList()); }
+      get { return allowedChildSymbolsPerIndex.Select(x => new KeyValuePair<Tuple<ISymbol, int>, IEnumerable<ISymbol>>(Tuple.Create(GetSymbol(x.Key.Item1), x.Key.Item2), x.Value.Select(GetSymbol).ToArray())).ToArray(); }
+      set {
+        foreach (var pair in value)
+          allowedChildSymbolsPerIndex.Add(Tuple.Create(pair.Key.Item1.Name, pair.Key.Item2), pair.Value.Select(y => y.Name).ToList());
+      }
     }
     #endregion
 
     private bool suppressEvents;
-    protected Dictionary<string, ISymbol> symbols;
-    protected Dictionary<string, Tuple<int, int>> symbolSubtreeCount;
-    protected Dictionary<string, List<string>> allowedChildSymbols;
-    protected Dictionary<Tuple<string, int>, List<string>> allowedChildSymbolsPerIndex;
+    protected readonly Dictionary<string, ISymbol> symbols;
+    protected readonly Dictionary<string, Tuple<int, int>> symbolSubtreeCount;
+    protected readonly Dictionary<string, List<string>> allowedChildSymbols;
+    protected readonly Dictionary<Tuple<string, int>, List<string>> allowedChildSymbolsPerIndex;
 
     public override bool CanChangeName {
@@ -87,4 +90,9 @@
       cachedIsAllowedChildSymbolIndex = new Dictionary<Tuple<string, string, int>, bool>();
 
+      symbols = new Dictionary<string, ISymbol>();
+      symbolSubtreeCount = new Dictionary<string, Tuple<int, int>>();
+      allowedChildSymbols = new Dictionary<string, List<string>>();
+      allowedChildSymbolsPerIndex = new Dictionary<Tuple<string, int>, List<string>>();
+
       suppressEvents = false;
     }
@@ -133,5 +141,5 @@
 
     #region protected grammar manipulation methods
-    protected virtual void AddSymbol(ISymbol symbol) {
+    public virtual void AddSymbol(ISymbol symbol) {
       if (ContainsSymbol(symbol)) throw new ArgumentException("Symbol " + symbol + " is already defined.");
       foreach (var s in symbol.Flatten()) {
@@ -143,5 +151,5 @@
     }
 
-    protected virtual void RemoveSymbol(ISymbol symbol) {
+    public virtual void RemoveSymbol(ISymbol symbol) {
       foreach (var s in symbol.Flatten()) {
         symbols.Remove(s.Name);
@@ -175,5 +183,5 @@
     }
 
-    protected void AddAllowedChildSymbol(ISymbol parent, ISymbol child) {
+    public virtual void AddAllowedChildSymbol(ISymbol parent, ISymbol child) {
       bool changed = false;
 
@@ -204,5 +212,5 @@
     }
 
-    protected void AddAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) {
+    public virtual void AddAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) {
       bool changed = false;
 
@@ -238,5 +246,5 @@
     }
 
-    protected void RemoveAllowedChildSymbol(ISymbol parent, ISymbol child) {
+    public virtual void RemoveAllowedChildSymbol(ISymbol parent, ISymbol child) {
       bool changed = false;
       List<string> childSymbols;
@@ -257,5 +265,5 @@
     }
 
-    protected void RemoveAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) {
+    public virtual void RemoveAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) {
       bool changed = false;
 
@@ -282,5 +290,5 @@
     }
 
-    protected void SetSubtreeCount(ISymbol symbol, int minimumSubtreeCount, int maximumSubtreeCount) {
+    public virtual void SetSubtreeCount(ISymbol symbol, int minimumSubtreeCount, int maximumSubtreeCount) {
       var symbols = symbol.Flatten().Where(s => !(s is GroupSymbol));
       if (symbols.Any(s => s.MinimumArity > minimumSubtreeCount)) throw new ArgumentException("Invalid minimum subtree count " + minimumSubtreeCount + " for " + symbol);
@@ -308,5 +316,5 @@
     }
     public virtual IEnumerable<ISymbol> AllowedSymbols {
-      get { foreach (var s in Symbols) if (s.Enabled) yield return s; }
+      get { return Symbols.Where(s => s.Enabled); }
     }
     public virtual bool ContainsSymbol(ISymbol symbol) {
@@ -330,7 +338,11 @@
         List<string> temp;
         if (allowedChildSymbols.TryGetValue(parent.Name, out temp)) {
-          if (temp.SelectMany(s => GetSymbol(s).Flatten()).Any(s => s.Name == child.Name)) {
-            cachedIsAllowedChildSymbol.Add(key, true);
-            return true;
+          for (int i = 0; i < temp.Count; i++) {
+            var symbol = GetSymbol(temp[i]);
+            foreach (var s in symbol.Flatten())
+              if (s.Name == child.Name) {
+                cachedIsAllowedChildSymbol.Add(key, true);
+                return true;
+              }
           }
         }
@@ -357,7 +369,11 @@
         List<string> temp;
         if (allowedChildSymbolsPerIndex.TryGetValue(Tuple.Create(parent.Name, argumentIndex), out temp)) {
-          if (temp.SelectMany(s => GetSymbol(s).Flatten()).Any(s => s.Name == child.Name)) {
-            cachedIsAllowedChildSymbolIndex.Add(key, true);
-            return true;
+          for (int i = 0; i < temp.Count; i++) {
+            var symbol = GetSymbol(temp[i]);
+            foreach (var s in symbol.Flatten())
+              if (s.Name == child.Name) {
+                cachedIsAllowedChildSymbolIndex.Add(key, true);
+                return true;
+              }
           }
         }
@@ -510,5 +526,5 @@
       if (suppressEvents) return;
       var handler = Changed;
-      if (handler != null) Changed(this, EventArgs.Empty);
+      if (handler != null) handler(this, EventArgs.Empty);
     }
   }
