Index: branches/New Persistence Exploration/Persistence/Persistence/DeSerializer.cs
===================================================================
--- branches/New Persistence Exploration/Persistence/Persistence/DeSerializer.cs	(revision 1338)
+++ branches/New Persistence Exploration/Persistence/Persistence/DeSerializer.cs	(revision 1339)
@@ -107,13 +107,13 @@
       if (FindCompoundSerializer(start.Type) != null) {
         instance = new ParentReference();
-        compositeStack.Push(new CustomObject(instance));
-        id2obj.Add(start.Id, instance);        
+        compositeStack.Push(new CustomObject(instance));        
       } else {        
         instance = Activator.CreateInstance(start.Type, true);
         Dictionary<string, DataMemberAccessor> accessorDict =
           StorableAttribute.GetAutostorableAccessors(instance);
-        compositeStack.Push(new CompositeObject(instance, accessorDict));
-        id2obj.Add(start.Id, instance);
+        compositeStack.Push(new CompositeObject(instance, accessorDict));        
       }
+      if ( start.Id != null )
+        id2obj.Add((int)start.Id, instance);
     }
     private void CompositeEndHandler(IParseToken token) {
@@ -124,5 +124,6 @@
         object deserializedObject =
           compoundSerializer.DeSerialize(customObject.customValues, end.Type);
-        id2obj[end.Id] = deserializedObject;        
+        if ( end.Id != null )
+          id2obj[(int)end.Id] = deserializedObject;        
         SetValue(end.Name, deserializedObject);          
       } else {
Index: branches/New Persistence Exploration/Persistence/Persistence/Serializer.cs
===================================================================
--- branches/New Persistence Exploration/Persistence/Persistence/Serializer.cs	(revision 1338)
+++ branches/New Persistence Exploration/Persistence/Persistence/Serializer.cs	(revision 1339)
@@ -12,4 +12,5 @@
     private readonly Dictionary<Type, IPrimitiveSerializer> primitiveSerializers;
     private readonly List<ICompoundSerializer> compoundSerializers;
+    private readonly Dictionary<Type, int> typeCache;
 
     public Serializer(object obj) :
@@ -34,5 +35,6 @@
       this.compoundSerializers = new List<ICompoundSerializer>(compoundSerializers);
       obj2id = new Dictionary<object, int> {{new object(), 0}};
-        }
+      typeCache = new Dictionary<Type, int>();
+    }
 
     IEnumerator IEnumerable.GetEnumerator() {
@@ -46,51 +48,69 @@
       while (iterator.MoveNext())
         yield return iterator.Current;
+      Console.WriteLine("TypeCache:f");
+      foreach ( var pair in typeCache )
+        Console.WriteLine(pair.Key);
     }
 
     private IEnumerator<ISerializationToken> Serialize(DataMemberAccessor accessor) {
+
       object value = accessor.Get();
+
       if (value == null) {
         yield return new NullReferenceToken(accessor.Name);
-      } else if (obj2id.ContainsKey(value)) {
+        yield break;
+      }
+
+      if (obj2id.ContainsKey(value)) {
         yield return new ReferenceToken(accessor.Name, obj2id[value]);
-      } else if (primitiveSerializers.ContainsKey(value.GetType())) {
-        int? id = null;
-        if ( ! value.GetType().IsValueType ) {
-          id = obj2id.Count;
-          obj2id.Add(value, (int)id);
-        }
+        yield break;
+      }
+
+      if ( ! typeCache.ContainsKey(value.GetType()))
+        typeCache.Add(value.GetType(), typeCache.Count);
+
+      int? id = null;
+      if ( ! value.GetType().IsValueType) {
+        id = obj2id.Count;
+        obj2id.Add(value, (int)id);
+      }
+
+      if (primitiveSerializers.ContainsKey(value.GetType())) {
+        
         yield return new PrimitiveToken(
           accessor,
           primitiveSerializers[value.GetType()].Serialize(value),
-          id);      
-      } else {
-        int id = obj2id.Count;
-        obj2id.Add(value, id);
-        yield return new BeginToken(accessor, id);
-        ICompoundSerializer customSerializer = FindCompoundSerializer(value.GetType());
-        if (customSerializer != null) {
-          foreach (object o in customSerializer.Serialize(value)) {
-            IEnumerator<ISerializationToken> iterator = Serialize(new DataMemberAccessor(o));
-            while (iterator.MoveNext())
-              yield return iterator.Current;
-          }
-        } else { // composite serialization
-          int nSubComponents = 0;
-          foreach (KeyValuePair<string, DataMemberAccessor> mapping in
-            StorableAttribute.GetAutostorableAccessors(value)) {
-            nSubComponents += 1;
-            IEnumerator<ISerializationToken> iterator = Serialize(mapping.Value);                        
-            while (iterator.MoveNext()) {                            
-              yield return iterator.Current;
-            }                        
-          }
-          if (nSubComponents == 0) {
-            throw new ApplicationException(String.Format(
-              "Composite value of type \"{0}\" contains no subcomponents",
-              value.GetType().FullName));
-          }
+          id);
+        yield break;
+      }
+      
+      yield return new BeginToken(accessor, id);
+      ICompoundSerializer customSerializer = FindCompoundSerializer(value.GetType());
+
+      if (customSerializer != null) {
+        foreach (object o in customSerializer.Serialize(value)) {
+          IEnumerator<ISerializationToken> iterator = Serialize(new DataMemberAccessor(o));
+          while (iterator.MoveNext())
+            yield return iterator.Current;
         }
         yield return new EndToken(accessor, id);
+        yield break;
       }
+
+      int nSubComponents = 0;
+      foreach (KeyValuePair<string, DataMemberAccessor> mapping in
+        StorableAttribute.GetAutostorableAccessors(value)) {
+        nSubComponents += 1;
+        IEnumerator<ISerializationToken> iterator = Serialize(mapping.Value);
+        while (iterator.MoveNext()) {
+          yield return iterator.Current;
+        }
+      }
+      if (nSubComponents == 0) {
+        throw new ApplicationException(String.Format(
+                                         "Composite value of type \"{0}\" contains no subcomponents",
+                                         value.GetType().FullName));
+      }
+      yield return new EndToken(accessor, id);
     }
 
Index: branches/New Persistence Exploration/Persistence/Persistence/Tokens.cs
===================================================================
--- branches/New Persistence Exploration/Persistence/Persistence/Tokens.cs	(revision 1338)
+++ branches/New Persistence Exploration/Persistence/Persistence/Tokens.cs	(revision 1339)
@@ -8,6 +8,6 @@
   public class BeginToken : ISerializationToken {
     public readonly DataMemberAccessor Accessor;
-    public readonly int Id;
-    public BeginToken(DataMemberAccessor accessor, int id) {
+    public readonly int? Id;
+    public BeginToken(DataMemberAccessor accessor, int? id) {
       Accessor = accessor;
       Id = id;
@@ -16,6 +16,6 @@
   public class EndToken : ISerializationToken {
     public readonly DataMemberAccessor Accessor;
-    public readonly int Id;
-    public EndToken(DataMemberAccessor accessor, int id) {
+    public readonly int? Id;
+    public EndToken(DataMemberAccessor accessor, int? id) {
       Accessor = accessor;
       Id = id;
@@ -55,6 +55,6 @@
     public readonly string Name;
     public readonly Type Type;
-    public readonly int Id;
-    public CompositeStart(string name, Type type, int id) {
+    public readonly int? Id;
+    public CompositeStart(string name, Type type, int? id) {
       Name = name;
       Type = type;
@@ -65,6 +65,6 @@
     public readonly string Name;
     public readonly Type Type;
-    public readonly int Id;
-    public CompositeEnd(string name, Type type, int id) {
+    public readonly int? Id;
+    public CompositeEnd(string name, Type type, int? id) {
       Name = name;
       Type = type;
Index: branches/New Persistence Exploration/Persistence/Persistence/XmlFormatter.cs
===================================================================
--- branches/New Persistence Exploration/Persistence/Persistence/XmlFormatter.cs	(revision 1338)
+++ branches/New Persistence Exploration/Persistence/Persistence/XmlFormatter.cs	(revision 1339)
@@ -1,5 +1,4 @@
 ﻿using System.Collections.Generic;
 using System;
-using System.Xml;
 using System.Text;
 namespace Persistence {
@@ -53,12 +52,11 @@
     private string FormatBegin(ISerializationToken token) {      
       BeginToken beginToken = (BeginToken)token;
+      var attributes = new Dictionary<string, string> {
+        {"name", beginToken.Accessor.Name},
+        {"type", beginToken.Accessor.Get().GetType().AssemblyQualifiedName } };
+      if ( beginToken.Id != null ) 
+        attributes.Add("id", beginToken.Id.ToString());                                           
       string result = Prefix +
-                      FormatNode("COMPOSITE",
-                                 new Dictionary<string, string>
-                                   {
-                                     {"name", beginToken.Accessor.Name},
-                                     {"type", beginToken.Accessor.Get().GetType().AssemblyQualifiedName},
-                                     {"id", beginToken.Id.ToString()}
-                                   }, NodeType.Start) + "\n";
+                      FormatNode("COMPOSITE", attributes, NodeType.Start) + "\n";
       depth += 1;
       return result;
Index: branches/New Persistence Exploration/Persistence/Persistence/XmlParser.cs
===================================================================
--- branches/New Persistence Exploration/Persistence/Persistence/XmlParser.cs	(revision 1338)
+++ branches/New Persistence Exploration/Persistence/Persistence/XmlParser.cs	(revision 1339)
@@ -59,5 +59,8 @@
       string name = reader.GetAttribute("name");      
       Type type = Type.GetType(reader.GetAttribute("type"));
-      int id = int.Parse(reader.GetAttribute("id"));
+      string idString = reader.GetAttribute("id");
+      int? id = null;
+      if (idString != null)
+        id = int.Parse(idString);      
       yield return new CompositeStart(name, type, id);
       IEnumerator<IParseToken> iterator = GetEnumerator();
