diff --git a/compiler/2014/CS_CodeGen.jrag b/compiler/2014/CS_CodeGen.jrag
index c05e6b2fe7456c5e748c6d87dc95b1cf1162233d..17fa08e336fcafa586ff7cd94d1694d0f216271b 100644
--- a/compiler/2014/CS_CodeGen.jrag
+++ b/compiler/2014/CS_CodeGen.jrag
@@ -13,7 +13,6 @@ aspect CS_CodeGenEnv {
     private int indent;
     private int depth;
     private CS_printer printer;
-    private HashMap unique = new HashMap();
 
     final private static class CS_printer {
       
@@ -159,15 +158,6 @@ aspect CS_CodeGenEnv {
       println("}");
     }
 
-    public String getUnique(Object o) {
-      String result = (String)unique.get(o);
-      if (result == null) {
-   	result = "_" + (unique.size() + 1) + "_";
-      }
-      unique.put(o, result);
-      return result;
-    }
-
   }
 
 }
@@ -377,6 +367,7 @@ aspect CS_Class {
     CS_emitSignature(env);
 
     env.println("}");
+    env.unindent();
   }
 
   public void Decl.CS_emitSignature(CS_env env) {
@@ -422,12 +413,12 @@ aspect CS_Class {
     env.unindent();
     env.println("}");
     env.println();
-    env.println("private class Dispatcher : SampleDispatcher{");
+    env.println("private class Dispatcher : SampleDispatcher {");
     env.indent();
     env.println();
-    env.println("public Type getSampleClass() {");
+    env.println("public SampleDispatcher getSampleIdentity() {");
     env.indent();
-    env.println("return typeof(" + getName() + ");");
+    env.println("return dispatcher;");
     env.unindent();
     env.println("}");
     env.println();
@@ -459,21 +450,6 @@ aspect CS_Class {
     env.unindent();
     env.println("}");
     env.println();
-//    env.println("public void encodeSignature(Encoder e) throws IOException{");
-//    env.indent();
-//    env.println("emitSignature(e);");
-//    env.unindent();
-//    env.println("}");
-//    env.println();
-//  env.println("public void encodeSignatureMetadata(Encoder e, int index){");
-//  env.indent();
-//  env.println("e.encodePacked32(Constant.TYPE_DEF);");
-//  env.println("e.encodePacked32(index);");
-//  env.println("e.encodeString(getName());");
-//  env.println("emitSignature(e);");
-//  env.unindent();
-//  env.println("}");
-//  env.println();
     env.println("public bool canDecodeAndHandle() {");
     env.indent();
     env.println("return "+isSample+";");
@@ -499,7 +475,6 @@ aspect CS_Class {
     env.unindent();
     env.println("}");
     env.println("");
-
  } //TODO, fix above method
   
   public void TypeDecl.CS_emitEncoder(CS_env env) {
@@ -526,9 +501,9 @@ aspect CS_Class {
     }
     env.println(") {");
     env.indent();
-    env.println("e.begin(typeof(" + getName() + "));");
+    env.println("e.begin(dispatcher);");
     getDataType().CS_emitEncoder(env, "value");
-    env.println("e.end(typeof(" + getName() + "));");
+    env.println("e.end(dispatcher);");
     env.unindent();
     env.println("}");
     env.println();
@@ -736,7 +711,7 @@ aspect CS_Class {
   public void PrimType.CS_emitTypePrefix(CS_env env) {
     switch (getToken()) {
       case LABCOMM_STRING: { env.print("String"); } break;
-      case LABCOMM_SAMPLE: { env.print("Type"); } break;
+      case LABCOMM_SAMPLE: { env.print("SampleDispatcher"); } break;
       default: { env.print(getName()); } break;
     }
   }
@@ -866,7 +841,7 @@ aspect CS_Class {
     switch (getToken()) {
       case LABCOMM_STRING: { env.print("String"); } break;
       case LABCOMM_BOOLEAN: { env.print("bool"); } break;
-      case LABCOMM_SAMPLE: { env.print("Type"); } break;
+      case LABCOMM_SAMPLE: { env.print("SampleDispatcher"); } break;
       default: { env.print(getName()); } break;
     }
   }
diff --git a/lib/csharp/Makefile b/lib/csharp/Makefile
index c689902e17402080d3f993ed7d9f00763c5967e1..0c67e052db39ee02344de066c159adf7648a9dba 100644
--- a/lib/csharp/Makefile
+++ b/lib/csharp/Makefile
@@ -1,4 +1,5 @@
-MODULES=Constant\
+MODULES=AbstractDecoder \
+        Constant\
 	Decoder \
 	DecoderChannel \
 	DecoderRegistry \
@@ -8,7 +9,7 @@ MODULES=Constant\
 	Sample \
 	SampleDispatcher \
 	SampleHandler \
-	SampleType 
+	SampleType
 
 .PHONY: all
 all: labcomm2014.dll
diff --git a/lib/csharp/se/lth/control/labcomm2014/AbstractDecoder.cs b/lib/csharp/se/lth/control/labcomm2014/AbstractDecoder.cs
new file mode 100644
index 0000000000000000000000000000000000000000..4ea8760333148a13838cb111949854a46e4b4820
--- /dev/null
+++ b/lib/csharp/se/lth/control/labcomm2014/AbstractDecoder.cs
@@ -0,0 +1,18 @@
+using System;
+
+namespace se.lth.control.labcomm2014 {
+
+  public interface AbstractDecoder {
+
+    void runOne();
+
+    void run();
+
+    void register(SampleDispatcher dispatcher, 
+		  SampleHandler handler);
+
+    void registerSampleRef(SampleDispatcher dispatcher);
+
+  }
+
+} 
diff --git a/lib/csharp/se/lth/control/labcomm2014/Decoder.cs b/lib/csharp/se/lth/control/labcomm2014/Decoder.cs
index ddc3b59f52fa9483332f5c358d00ee4a18d92dcf..0d79bcab539a512205fe0c40e7fe16296f8feb5e 100644
--- a/lib/csharp/se/lth/control/labcomm2014/Decoder.cs
+++ b/lib/csharp/se/lth/control/labcomm2014/Decoder.cs
@@ -2,11 +2,7 @@ using System;
 
 namespace se.lth.control.labcomm2014 {
 
-  public interface Decoder {
-
-    void register(SampleDispatcher dispatcher, 
-		  SampleHandler handler);
-    void registerSampleRef(SampleDispatcher dispatcher);
+  public interface Decoder : AbstractDecoder {
 
     bool decodeBoolean();
     byte decodeByte();
@@ -17,7 +13,7 @@ namespace se.lth.control.labcomm2014 {
     double decodeDouble();
     String decodeString();
     int decodePacked32();
-    Type decodeSampleRef();
+    SampleDispatcher decodeSampleRef();
 
   }
 
diff --git a/lib/csharp/se/lth/control/labcomm2014/DecoderChannel.cs b/lib/csharp/se/lth/control/labcomm2014/DecoderChannel.cs
index a56a6042af37e455eea0766e82901264714e93b3..4c02d834ea764a0fdc75f178b33da719b17f8de5 100644
--- a/lib/csharp/se/lth/control/labcomm2014/DecoderChannel.cs
+++ b/lib/csharp/se/lth/control/labcomm2014/DecoderChannel.cs
@@ -166,11 +166,11 @@ namespace se.lth.control.labcomm2014 {
       return (int) (res & 0xffffffff);
     }
 
-    public Type decodeSampleRef() {
+    public SampleDispatcher decodeSampleRef() {
       int index = (int)ReadInt(4);
       try {
         DecoderRegistry.Entry e = ref_registry.get(index);
-        return e.getSampleDispatcher().getSampleClass();
+        return e.getSampleDispatcher().getSampleIdentity();
       } catch (NullReferenceException) {
         return null;
       }
diff --git a/lib/csharp/se/lth/control/labcomm2014/DecoderRegistry.cs b/lib/csharp/se/lth/control/labcomm2014/DecoderRegistry.cs
index bebcff26c7355a184b471234ca85f72043d0f493..6c7a4a49fc5d4d66336015cacceeb259bb637784 100644
--- a/lib/csharp/se/lth/control/labcomm2014/DecoderRegistry.cs
+++ b/lib/csharp/se/lth/control/labcomm2014/DecoderRegistry.cs
@@ -90,11 +90,11 @@ namespace se.lth.control.labcomm2014 {
       }
     }
 
-    private Dictionary<Type, Entry> byClass;
+    private Dictionary<SampleDispatcher, Entry> byIdentity;
     private Dictionary<int, Entry> byIndex;
 
     public DecoderRegistry() {
-      byClass = new Dictionary<Type, Entry>();
+      byIdentity = new Dictionary<SampleDispatcher, Entry>();
       byIndex = new Dictionary<int, Entry>();
     }
 
@@ -102,7 +102,7 @@ namespace se.lth.control.labcomm2014 {
 		    SampleHandler handler) {
       lock(this) {
 	Entry e;
-	byClass.TryGetValue(dispatcher.getSampleClass(), out e);
+	byIdentity.TryGetValue(dispatcher.getSampleIdentity(), out e);
 	if (e != null) {
 	  e.check(dispatcher.getName(), dispatcher.getSignature());
 	  e.setHandler(handler);
@@ -117,7 +117,7 @@ namespace se.lth.control.labcomm2014 {
 	  }
 	  if (e == null) {
 	    e = new Entry(dispatcher, handler);
-	    byClass.Add(dispatcher.getSampleClass(), e);
+	    byIdentity.Add(dispatcher.getSampleIdentity(), e);
 	  }
 	}
       }
@@ -132,7 +132,7 @@ namespace se.lth.control.labcomm2014 {
 	if (e != null) {
 	  e.check(name, signature);
 	} else {
-	  foreach (Entry e2 in byClass.Values) {
+	  foreach (Entry e2 in byIdentity.Values) {
 	    if (e2.match(name, signature)) {
 	      e2.setIndex(index);
 	      e = e2;
diff --git a/lib/csharp/se/lth/control/labcomm2014/Encoder.cs b/lib/csharp/se/lth/control/labcomm2014/Encoder.cs
index 4aac7b3ac949019684b969d462cf8d93b0b4c4e7..08d77514037bc3bfdd1c1526f60c91b653bd1790 100644
--- a/lib/csharp/se/lth/control/labcomm2014/Encoder.cs
+++ b/lib/csharp/se/lth/control/labcomm2014/Encoder.cs
@@ -6,8 +6,8 @@ namespace se.lth.control.labcomm2014 {
     
     void register(SampleDispatcher dispatcher);
     void registerSampleRef(SampleDispatcher dispatcher);
-    void begin(Type c);
-    void end(Type c);
+    void begin(SampleDispatcher dispatcher);
+    void end(SampleDispatcher dispatcher);
 
     void encodeBoolean(bool value);
     void encodeByte(byte value);
@@ -18,7 +18,7 @@ namespace se.lth.control.labcomm2014 {
     void encodeDouble(double value);
     void encodeString(String value);
     void encodePacked32(Int64 value);
-    void encodeSampleRef(Type value);
+    void encodeSampleRef(SampleDispatcher value);
     
   }
 
diff --git a/lib/csharp/se/lth/control/labcomm2014/EncoderChannel.cs b/lib/csharp/se/lth/control/labcomm2014/EncoderChannel.cs
index 20536e4d79c192deba72cd20958554eb51a93939..cba6072bef586dad8051b25f90eba45ef03ca39b 100644
--- a/lib/csharp/se/lth/control/labcomm2014/EncoderChannel.cs
+++ b/lib/csharp/se/lth/control/labcomm2014/EncoderChannel.cs
@@ -53,11 +53,11 @@ namespace se.lth.control.labcomm2014 {
       bytes.SetLength(0);
     }
 
-    public void begin(Type c) {
-      begin(def_registry.getTag(c));
+    public void begin(SampleDispatcher identity) {
+      begin(def_registry.getTag(identity));
     }
 
-    public void end(Type c) {
+    public void end(SampleDispatcher identity) {
       WritePacked32(writer, current_tag);
       WritePacked32(writer, bytes.Length);
       bytes.WriteTo(writer);
@@ -132,7 +132,7 @@ namespace se.lth.control.labcomm2014 {
       WritePacked32(bytes, value);
     }
 
-    public void encodeSampleRef(Type value) {
+    public void encodeSampleRef(SampleDispatcher value) {
       int index = 0;
       try {
         index = ref_registry.getTag(value);
diff --git a/lib/csharp/se/lth/control/labcomm2014/EncoderRegistry.cs b/lib/csharp/se/lth/control/labcomm2014/EncoderRegistry.cs
index 5d35ecb17235e656c258e8953862e719cd84653a..72ec5f2bb606525014e7e85725b99525b0b6954d 100644
--- a/lib/csharp/se/lth/control/labcomm2014/EncoderRegistry.cs
+++ b/lib/csharp/se/lth/control/labcomm2014/EncoderRegistry.cs
@@ -26,29 +26,29 @@ namespace se.lth.control.labcomm2014 {
     }
 
     private int userIndex = Constant.FIRST_USER_INDEX;
-    private Dictionary<Type, Entry> byClass;
+    private Dictionary<SampleDispatcher, Entry> byIdentity;
 
     public EncoderRegistry() {
-      byClass = new Dictionary<Type, Entry>();
+      byIdentity = new Dictionary<SampleDispatcher, Entry>();
     }
 
     public int add(SampleDispatcher dispatcher) {
       lock(this) {
 	Entry e;
-	byClass.TryGetValue(dispatcher.getSampleClass(), out e);
+	byIdentity.TryGetValue(dispatcher.getSampleIdentity(), out e);
 	if (e == null) {
 	  e = new Entry(dispatcher, userIndex);
-	  byClass.Add(dispatcher.getSampleClass(), e);
+	  byIdentity.Add(dispatcher.getSampleIdentity(), e);
 	  userIndex++;
 	}
 	return e.getIndex();
       }
     }
   
-    public int getTag(Type sample) {
+    public int getTag(SampleDispatcher sample) {
       lock(this) {
 	Entry e;
-	byClass.TryGetValue(sample, out e);
+	byIdentity.TryGetValue(sample, out e);
 	if (e == null) {
 	  throw new Exception("'" + 
 			      sample.ToString() + 
diff --git a/lib/csharp/se/lth/control/labcomm2014/SampleDispatcher.cs b/lib/csharp/se/lth/control/labcomm2014/SampleDispatcher.cs
index b7104d1c28c98e4607858fd6e7958fd5a7022122..de405d1505371766aced4e00462c297942e1a0b1 100644
--- a/lib/csharp/se/lth/control/labcomm2014/SampleDispatcher.cs
+++ b/lib/csharp/se/lth/control/labcomm2014/SampleDispatcher.cs
@@ -4,12 +4,12 @@ namespace se.lth.control.labcomm2014 {
 
   public interface SampleDispatcher {
     
-    Type getSampleClass();
+    SampleDispatcher getSampleIdentity();
     
     String getName();
     
     byte[] getSignature();
-    
+
     void decodeAndHandle(Decoder decoder,
 			 SampleHandler handler);