- system-set classes use IDs starting at 1024
- Cosmas OPBED serialised using matches-Positions rather than 0-word-distances
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractSyntaxTree.java b/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractSyntaxTree.java
index ec93a84..5f1b2d8 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractSyntaxTree.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractSyntaxTree.java
@@ -189,10 +189,20 @@
 	}
 	
 	protected LinkedHashMap<String, Object> makeSpanClass(int classCount) {
+		return makeSpanClass(classCount, true);
+	}
+	
+	protected LinkedHashMap<String, Object> makeSpanClass(int classCount, boolean setBySystem) {
 		LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
 		group.put("@type", "korap:group");
 		group.put("operation", "operation:class");
-		group.put("class", classCount);
+		if (setBySystem) {
+			group.put("class", 1024+classCount);
+			announcements.add("A class has been introduced into the backend representation of " +
+					"your query for later reference to a part of the query. The class id is "+classCount);
+		} else {
+			group.put("class", classCount);
+		}
 		group.put("operands", new ArrayList<Object>());
 		return group;
 	}
@@ -284,7 +294,7 @@
 
 	@SuppressWarnings("unchecked")
 	protected LinkedHashMap<String, Object> wrapInClass(LinkedHashMap<String, Object> group, Integer classId) {
-		LinkedHashMap<String, Object> classGroup = makeSpanClass(classId);
+		LinkedHashMap<String, Object> classGroup = makeSpanClass(classId, true);
 		((ArrayList<Object>) classGroup.get("operands")).add(group);
 		return classGroup;
 	}
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CosmasTree.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CosmasTree.java
index e6c2a05..feb6337 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/CosmasTree.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CosmasTree.java
@@ -453,9 +453,9 @@
             LinkedHashMap<String, Object> embeddedSequence = group;
             
             if (! (openNodeCats.get(1).equals("OPBEG") || openNodeCats.get(1).equals("OPEND") || openNodeCats.get(1).equals("OPALL") || openNodeCats.get(1).equals("OPNHIT"))) {
-                wrapOperandInClass(node,1,0);
-                wrapOperandInClass(node,2,0);
-                group = wrapInReference(group, 0);
+                wrapOperandInClass(node,1,classCounter);
+                wrapOperandInClass(node,2,classCounter);
+                group = wrapInReference(group, 1024+classCounter++);
             }
             
             LinkedHashMap<String,Object> sequence = null;
@@ -508,7 +508,7 @@
             invertedOperandsLists.push((ArrayList<Object>) posgroup.get("operands"));
             stackedObjects++;
             // Step II: wrap in reference (limit match to first argument) and decide where to put
-            LinkedHashMap<String, Object> submatchgroup = wrapInReference(posgroup, classCounter);
+            LinkedHashMap<String, Object> submatchgroup = wrapInReference(posgroup, 1024+classCounter);
             putIntoSuperObject(submatchgroup, 1);
         }
 
@@ -533,14 +533,14 @@
 
         if (nodeCat.equals("OPNHIT")) {
             ArrayList<Integer> classRef = new ArrayList<Integer>();
-            classRef.add(classCounter);
+            classRef.add(1024+classCounter);
 //            classRef.add(classCounter + 1);  // yes, do this twice (two classes)!
             LinkedHashMap<String, Object> group = makeReference(classRef);
             group.put("classRefOp", "classRefOp:inversion");
             ArrayList<Object> operands = new ArrayList<Object>();
             group.put("operands", operands);
-            wrapOperandInClass(node.getChild(0),1,classCounter); // direct child is OPPROX
-            wrapOperandInClass(node.getChild(0),2,classCounter++);
+            wrapOperandInClass(node.getChild(0),1,1024+classCounter); // direct child is OPPROX
+            wrapOperandInClass(node.getChild(0),2,1024+classCounter++);
             objectStack.push(group);
             stackedObjects++;
             putIntoSuperObject(group, 1);
@@ -576,7 +576,7 @@
             // create a containing group expressing the submatch constraint on the first argument
             ArrayList<Integer> spanRef = new ArrayList<Integer>();
             spanRef.add(1);
-            LinkedHashMap<String, Object> submatchgroup = makeReference(spanRef);
+            LinkedHashMap<String, Object> submatchgroup = makeReference(1024+classCounter);
             ArrayList<Object> submatchoperands = new ArrayList<Object>();
             submatchgroup.put("operands", submatchoperands);
             putIntoSuperObject(submatchgroup);
@@ -611,11 +611,11 @@
                 //     use 'focus' operations to create nested conditions
             } else {
                 // node has several conditions (like 'sa, -pa')
-                // -> create zero-distance sequence group and embed all position groups there
-                LinkedHashMap<String, Object> conjunct = makeGroup("sequence");
-                ArrayList<Object> distances = new ArrayList<Object>();
-                distances.add(makeDistance("w", 0,0));
-                conjunct.put("distances", distances);
+                // -> create identity position group and embed all position groups there
+                LinkedHashMap<String, Object> conjunct = makePosition(new String[]{"frame:matches"}, new String[]{"sharedClasses:equals"});
+//                ArrayList<Object> distances = new ArrayList<Object>();
+//                distances.add(makeDistance("w", 0,0));
+//                conjunct.put("distances", distances);
                 ArrayList<Object> operands = new ArrayList<Object>();
                 conjunct.put("operands", operands);
                 ArrayList<Object> distributedOperands = new ArrayList<Object>();
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusTree.java b/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusTree.java
index 5d136b7..8124abc 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusTree.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusTree.java
@@ -101,6 +101,7 @@
 		if (nodeCat.equals("sequence")) {
 			LinkedHashMap<String,Object> sequence = makeGroup("sequence");
 			ParseTree distanceNode = getFirstChildWithCat(node, "distance");
+			
 			if (distanceNode!=null) {
 				Integer[] minmax = parseDistance(distanceNode);
 				LinkedHashMap<String,Object> distance = makeDistance("w", minmax[0], minmax[1]);
@@ -134,6 +135,18 @@
 			stackedObjects++;
 		}
 		
+		if (nodeCat.equals("emptyTokenSequenceClass")) {
+			Integer[] minmax = parseDistance(node);
+			int classId = 0;
+			if (hasChild(node, "spanclass_id")) {
+				classId = Integer.parseInt(node.getChild(1).getChild(0).toStringTree(parser));
+			}
+			LinkedHashMap<String,Object> classGroup = makeSpanClass(classId, false);
+			putIntoSuperObject(classGroup);
+			objectStack.push(classGroup);
+			stackedObjects++;
+		}
+		
 
 		if (nodeCat.equals("token")) {
 			LinkedHashMap<String,Object> token = makeToken();
@@ -287,7 +300,7 @@
 					classId = 0;
 				}
 			}
-			LinkedHashMap<String, Object> classGroup = makeSpanClass(classId);
+			LinkedHashMap<String, Object> classGroup = makeSpanClass(classId, false);
 			putIntoSuperObject(classGroup);
 			objectStack.push(classGroup);
 			stackedObjects++;
@@ -592,7 +605,8 @@
 	 * @return
 	 */
 	private Integer[] parseDistance(ParseTree distanceNode) {
-		Integer[] minmax = parseEmptySegments(distanceNode.getChild(0));
+		int emptyTokenSeqIndex = getNodeCat(distanceNode).equals("distance") ? 0 : 2; 
+		Integer[] minmax = parseEmptySegments(distanceNode.getChild(emptyTokenSeqIndex));
 		Integer min = minmax[0];
 		Integer max = minmax[1];
 		min++;
diff --git a/src/test/java/CosmasTreeTest.java b/src/test/java/CosmasTreeTest.java
index e7eec87..f5f494a 100644
--- a/src/test/java/CosmasTreeTest.java
+++ b/src/test/java/CosmasTreeTest.java
@@ -210,13 +210,13 @@
 	public void testOPPROX() throws QueryException {
 		query="Sonne /+w1:4 Mond";
 		String prox1 = 
-					"{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+					"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 						"{@type=korap:group, operation=operation:sequence, " +
 							"operands=[" +
-								"{@type=korap:group, operation=operation:class, class=0, operands=[" +
+								"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 									"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
 								"]}," +
-								"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+								"{@type=korap:group, operation=operation:class, class=1025, operands=[" +	
 									"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
 								"]}" +
 							"], inOrder=true, " +
@@ -231,13 +231,13 @@
 		
 		query="Sonne /+w1:4,s0,p1:3 Mond";
 		String prox2 = 
-				"{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+				"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 					"{@type=korap:group, operation=operation:sequence, " +
 						"operands=[" +
-							"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+							"{@type=korap:group, operation=operation:class, class=1025, operands=[" +	
 								"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
 							"]}," +
-							"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+							"{@type=korap:group, operation=operation:class, class=1025, operands=[" +	
 								"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
 							"]}" +
 						"], inOrder=true, " +
@@ -254,13 +254,13 @@
 		
 		query="Sonne %+w1:4,s0,p1:3 Mond";
 		String prox3 = 
-				"{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+				"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 					"{@type=korap:group, operation=operation:sequence, " +
 						"operands=[" +
-							"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+							"{@type=korap:group, operation=operation:class, class=1025, operands=[" +	
 								"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
 							"]}," +
-							"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+							"{@type=korap:group, operation=operation:class, class=1025, operands=[" +	
 								"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
 							"]}" +
 						"], inOrder=true, " +
@@ -277,13 +277,13 @@
 		
 		query="Sonne /+w4 Mond";
 		String prox4 = 
-						"{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+						"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 							"{@type=korap:group, operation=operation:sequence, " +
 								"operands=[" +
-									"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+									"{@type=korap:group, operation=operation:class, class=1025, operands=[" +	
 										"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
 									"]}," +
-									"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+									"{@type=korap:group, operation=operation:class, class=1025, operands=[" +	
 										"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
 									"]}" +
 								"], inOrder=true, " +
@@ -294,20 +294,20 @@
 						"]}";
 //					"{@type=korap:group, operation=operation:or, operands=[" +
 //						"{@type=korap:group, operation=operation:position, frames=[frame:], sharedClasses=[sharedClasses:intersects], operands=[" +
-//							"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+//							"{@type=korap:group, operation=operation:class, class=1024, operands=[" +	
 //								"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
 //							"]}," +
-//							"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+//							"{@type=korap:group, operation=operation:class, class=1024, operands=[" +	
 //								"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
 //							"]}" +
 //						"], frame=frame:overlaps}," +
-//						"{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+//						"{@type=korap:reference, operation=operation:focus, classRef=[1024], operands=[" +
 //							"{@type=korap:group, operation=operation:sequence, " +
 //								"operands=[" +
-//									"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+//									"{@type=korap:group, operation=operation:class, class=1024, operands=[" +	
 //										"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
 //									"]}," +
-//									"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+//									"{@type=korap:group, operation=operation:class, class=1024, operands=[" +	
 //										"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
 //									"]}" +
 //								"], inOrder=true, " +
@@ -325,13 +325,13 @@
 		
 		query="Sonne /-w4 Mond";
 		String prox5 = 
-					"{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+					"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 						"{@type=korap:group, operation=operation:sequence, " +
 							"operands=[" +
-								"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+								"{@type=korap:group, operation=operation:class, class=1025, operands=[" +	
 									"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
 								"]}," +
-								"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+								"{@type=korap:group, operation=operation:class, class=1025, operands=[" +	
 									"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
 								"]}" +
 							"], inOrder=true, " +
@@ -342,20 +342,20 @@
 					"]}";
 //				"{@type=korap:group, operation=operation:or, operands=[" +
 //					"{@type=korap:group, operation=operation:position, frames=[frame:], sharedClasses=[sharedClasses:intersects], operands=[" +
-//						"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+//						"{@type=korap:group, operation=operation:class, class=1024, operands=[" +	
 //							"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
 //						"]}," +
-//						"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+//						"{@type=korap:group, operation=operation:class, class=1024, operands=[" +	
 //							"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
 //						"]}" +
 //					"], frame=frame:overlaps}," +
-//					"{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+//					"{@type=korap:reference, operation=operation:focus, classRef=[1024], operands=[" +
 //						"{@type=korap:group, operation=operation:sequence, " +
 //							"operands=[" +
-//								"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+//								"{@type=korap:group, operation=operation:class, class=1024, operands=[" +	
 //									"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
 //								"]}," +
-//								"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+//								"{@type=korap:group, operation=operation:class, class=1024, operands=[" +	
 //									"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
 //								"]}" +
 //							"], inOrder=true, " +
@@ -371,13 +371,13 @@
 		
 		query="Sonne /w4 Mond";
 		String prox6 = 
-					"{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+					"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 						"{@type=korap:group, operation=operation:sequence, " +
 							"operands=[" +
-								"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+								"{@type=korap:group, operation=operation:class, class=1025, operands=[" +	
 									"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
 								"]}," +
-								"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+								"{@type=korap:group, operation=operation:class, class=1025, operands=[" +	
 									"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
 								"]}" +
 							"], inOrder=false, " +
@@ -388,20 +388,20 @@
 					"]}";
 //				"{@type=korap:group, operation=operation:or, operands=[" +
 //					"{@type=korap:group, operation=operation:position, frames=[frame:], sharedClasses=[sharedClasses:intersects], operands=[" +
-//						"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+//						"{@type=korap:group, operation=operation:class, class=1024, operands=[" +	
 //							"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
 //						"]}," +
-//						"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+//						"{@type=korap:group, operation=operation:class, class=1024, operands=[" +	
 //							"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
 //						"]}" +
 //					"], frame=frame:overlaps}," +
-//					"{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+//					"{@type=korap:reference, operation=operation:focus, classRef=[1024], operands=[" +
 //						"{@type=korap:group, operation=operation:sequence, " +
 //							"operands=[" +
-//								"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+//								"{@type=korap:group, operation=operation:class, class=1024, operands=[" +	
 //									"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
 //								"]}," +
-//								"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+//								"{@type=korap:group, operation=operation:class, class=1024, operands=[" +	
 //									"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
 //								"]}" +
 //							"], inOrder=false, " +
@@ -420,20 +420,20 @@
 	public void testOPPROXNested() throws QueryException {	
 		query="Sonne /+w1:4 Mond /-w1:7 Sterne";
 		expected = 
-					"{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+					"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 						"{@type=korap:group, operation=operation:sequence, " +
 							"operands=[" +
-								"{@type=korap:group, operation=operation:class, class=0, operands=[" +
+								"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 									"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
 								"]}," +
-								"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
-									"{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+								"{@type=korap:group, operation=operation:class, class=1025, operands=[" +	
+									"{@type=korap:reference, operation=operation:focus, classRef=[1026], operands=[" +
 										"{@type=korap:group, operation=operation:sequence, " +
 											"operands=[" +
-												"{@type=korap:group, operation=operation:class, class=0, operands=[" +
+												"{@type=korap:group, operation=operation:class, class=1026, operands=[" +
 													"{@type=korap:token, wrap={@type=korap:term, key=Sterne, layer=orth, match=match:eq}}" +
 												"]}," +
-												"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+												"{@type=korap:group, operation=operation:class, class=1026, operands=[" +	
 													"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
 												"]}" +
 											"], inOrder=true, " +
@@ -461,10 +461,10 @@
 //					"{@type=korap:token, wrap={@type=korap:term, key=Sterne, layer=orth, match=match:eq}}" ;
 		
 		String mondsterneClasses = 
-					"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+					"{@type=korap:group, operation=operation:class, class=1024, operands=[" +	
 						"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
 					"]}," +
-					"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+					"{@type=korap:group, operation=operation:class, class=1024, operands=[" +	
 						"{@type=korap:token, wrap={@type=korap:term, key=Sterne, layer=orth, match=match:eq}}" +
 					"]}";
 //		String mondsterneSeq = 
@@ -474,7 +474,7 @@
 //						"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=2}, min=1, max=2}" +
 //					"]}" ;
 		String mondsterneClassesSeq = 
-				"{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+				"{@type=korap:reference, operation=operation:focus, classRef=[1024], operands=[" +
 					"{@type=korap:group, operation=operation:sequence, operands=[" +
 						mondsterneClasses +
 					"], inOrder=true, distances=[" +
@@ -500,17 +500,17 @@
 		
 		
 		String prox6 = 
-				"{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+				"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 						"{@type=korap:group, operation=operation:sequence, " +
 							"operands=[" +
-								"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
-									"{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+								"{@type=korap:group, operation=operation:class, class=1025, operands=[" +	
+									"{@type=korap:reference, operation=operation:focus, classRef=[1026], operands=[" +
 										"{@type=korap:group, operation=operation:sequence, " +
 											"operands=[" +
-												"{@type=korap:group, operation=operation:class, class=0, operands=[" +
+												"{@type=korap:group, operation=operation:class, class=1026, operands=[" +
 													"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
 												"]}," +
-												"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+												"{@type=korap:group, operation=operation:class, class=1026, operands=[" +	
 													"{@type=korap:token, wrap={@type=korap:term, key=Sterne, layer=orth, match=match:eq}}" +
 												"]}" +
 											"], inOrder=true, " +
@@ -520,7 +520,7 @@
 										"}" +
 									"]}" +
 								"]}," +
-								"{@type=korap:group, operation=operation:class, class=0, operands=[" +
+								"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 									"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
 								"]}" +
 							"], inOrder=true, " +
@@ -532,20 +532,20 @@
 					""	;
 //			"{@type=korap:group, operation=operation:or, operands=[" +
 //				"{@type=korap:group, operation=operation:position, frames=[frame:], sharedClasses=[sharedClasses:intersects], operands=[" +
-//					"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+//					"{@type=korap:group, operation=operation:class, class=1024, operands=[" +	
 //						mondsterneAllClasses  + 
 //					"]}," +
-//					"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+//					"{@type=korap:group, operation=operation:class, class=1024, operands=[" +	
 //						"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
 //					"]}" +
 //				"], frame=frame:overlaps}," +
-//				"{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+//				"{@type=korap:reference, operation=operation:focus, classRef=[1024], operands=[" +
 //					"{@type=korap:group, operation=operation:sequence, " +
 //						"operands=[" +
-//							"{@type=korap:group, operation=operation:class, class=0, operands=[" +	
+//							"{@type=korap:group, operation=operation:class, class=1024, operands=[" +	
 //								mondsterneAllClasses  + 
 //							"]}," +
-//							"{@type=korap:group, operation=operation:class, class=0, operands=[" +
+//							"{@type=korap:group, operation=operation:class, class=1024, operands=[" +
 //								"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
 //							"]}" +
 //						"], inOrder=true, " +
@@ -564,10 +564,10 @@
 	public void testOPIN() throws QueryException {
 		query="wegen #IN <s>";
 		String opin1 = 
-					"{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
+					"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 						"{@type=korap:group, operation=operation:position, operands=[" +
 							"{@type=korap:span, key=s}," +
-							"{@type=korap:group, operation=operation:class, class=1, operands=[" +
+							"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 								"{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
 							"]}" +
 						"], frames=[], sharedClasses=[sharedClasses:includes], frame=frame:contains}" +
@@ -578,10 +578,10 @@
 		
 		query="wegen #IN(L) <s>"; 
 		String opin2 = 
-					"{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
+					"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 						"{@type=korap:group, operation=operation:position, operands=[" +
 							"{@type=korap:span, key=s}," +
-							"{@type=korap:group, operation=operation:class, class=1, operands=[" +
+							"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 								"{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
 							"]}" +
 						"], frames=[frame:startswith], sharedClasses=[sharedClasses:includes], frame=frame:startswith}" +
@@ -593,10 +593,10 @@
 		
 		query="wegen #IN(F) <s>";
 		String opin3= 
-					"{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
+					"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 						"{@type=korap:group, operation=operation:position, operands=[" +
 							"{@type=korap:span, key=s}," +
-							"{@type=korap:group, operation=operation:class, class=1, operands=[" +
+							"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 								"{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
 							"]}" +
 						"], frames=[frame:matches], sharedClasses=[sharedClasses:includes], frame=frame:matches}" +
@@ -608,10 +608,10 @@
 		
 		query="wegen #IN(FI) <s>";
 		String opin4= 
-					"{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
+					"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 						"{@type=korap:group, operation=operation:position, operands=[" +
 							"{@type=korap:span, key=s}," +
-							"{@type=korap:group, operation=operation:class, class=1, operands=[" +
+							"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 								"{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
 							"]}" +
 						"], frames=[frame:matches], sharedClasses=[sharedClasses:unequals,sharedClasses:includes], frame=frame:matches-noident}" +
@@ -623,10 +623,10 @@
 		
 		query="wegen #IN(FE) <s>";
 		String opin5= 
-				"{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
+				"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 						"{@type=korap:group, operation=operation:position, operands=[" +
 							"{@type=korap:span, key=s}," +
-							"{@type=korap:group, operation=operation:class, class=1, operands=[" +
+							"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 								"{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
 							"]}" +
 						"], frames=[frame:matches], sharedClasses=[sharedClasses:equals], frame=frame:matches}" +
@@ -638,10 +638,10 @@
 		
 		query="wegen #IN(%, L) <s>";
 		String opin6 = 
-					"{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
+					"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 						"{@type=korap:group, operation=operation:position, operands=[" +
 							"{@type=korap:span, key=s}," +
-							"{@type=korap:group, operation=operation:class, class=1, operands=[" +
+							"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 								"{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
 							"]}" +
 						"], frames=[frame:startswith], sharedClasses=[sharedClasses:includes], frame=frame:startswith, exclude=true}" +
@@ -652,12 +652,12 @@
 		
 		query="wegen #IN('FE,ALL,%,MIN') <s>";
 		String opin7 = 
-					"{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
+					"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 						"{@type=korap:group, operation=operation:position, operands=[" +
 							"{@type=korap:reference, operation=operation:focus, reset=true, operands=[" +
 								"{@type=korap:span, key=s}" +
 							"]}," +
-							"{@type=korap:group, operation=operation:class, class=1, operands=[" +
+							"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 								"{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
 							"]}" +
 						"], frames=[frame:matches], sharedClasses=[sharedClasses:equals], frame=frame:matches, exclude=true, grouping=false}" +
@@ -671,10 +671,10 @@
 	public void testOPOV() throws QueryException {
 		query="wegen #OV <s>";
 		String opov1 = 
-					"{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
+					"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 						"{@type=korap:group, operation=operation:position, operands=[" +
 							"{@type=korap:span, key=s}," +
-							"{@type=korap:group, operation=operation:class, class=1, operands=[" +
+							"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 								"{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
 							"]}" +
 						"], frames=[], sharedClasses=[sharedClasses:intersects], frame=frame:overlaps}" +
@@ -685,10 +685,10 @@
 		
 		query="wegen #OV(L) <s>";
 		String opov2 = 
-					"{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
+					"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 						"{@type=korap:group, operation=operation:position, operands=[" +
 							"{@type=korap:span, key=s}," +
-							"{@type=korap:group, operation=operation:class, class=1, operands=[" +
+							"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 								"{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
 							"]}" +
 						"], frames=[frame:startswith,frame:overlapsLeft], sharedClasses=[sharedClasses:intersects], frame=frame:overlapsLeft}" +
@@ -699,10 +699,10 @@
 		
 		query="wegen #OV(F) <s>";
 		String opov3= 
-					"{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
+					"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 						"{@type=korap:group, operation=operation:position, operands=[" +
 							"{@type=korap:span, key=s}," +
-							"{@type=korap:group, operation=operation:class, class=1, operands=[" +
+							"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 								"{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
 							"]}" +
 						"], frames=[frame:matches], sharedClasses=[sharedClasses:intersects], frame=frame:matches}" +
@@ -713,10 +713,10 @@
 		
 		query="wegen #OV(FI) <s>";
 		String opov4= 
-					"{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
+					"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 						"{@type=korap:group, operation=operation:position, operands=[" +
 							"{@type=korap:span, key=s}," +
-							"{@type=korap:group, operation=operation:class, class=1, operands=[" +
+							"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 								"{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
 							"]}" +
 						"], frames=[frame:matches], sharedClasses=[sharedClasses:unequals], frame=frame:matches-noident}" +
@@ -727,10 +727,10 @@
 		
 		query="wegen #OV(FE) <s>";
 		String opov5= 
-							"{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
+							"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 								"{@type=korap:group, operation=operation:position, operands=[" +
 									"{@type=korap:span, key=s}," +
-									"{@type=korap:group, operation=operation:class, class=1, operands=[" +
+									"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 										"{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
 									"]}" +
 								"], frames=[frame:matches], sharedClasses=[sharedClasses:equals], frame=frame:matches}" +
@@ -780,10 +780,10 @@
 		
 //		String dermannSeq = "{@type=korap:group, operation=operation:sequence," +
 //								"operands = [" +
-//									"{@type=korap:group, operation=operation:class, class=0, operands=[" +
+//									"{@type=korap:group, operation=operation:class, class=1024, operands=[" +
 //										"{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}" +
 //									"]}," +
-//									"{@type=korap:group, operation=operation:class, class=0, operands=[" +
+//									"{@type=korap:group, operation=operation:class, class=1024, operands=[" +
 //										"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
 //									"]}" +
 //									
@@ -792,7 +792,7 @@
 //								"]}";
 //		
 //		String begDermannSeq = 
-////							"{@type=korap:group, operation=operation:class, class=0, operands=[" +
+////							"{@type=korap:group, operation=operation:class, class=1024, operands=[" +
 //								"{@type=korap:reference, operation=operation:focus, spanRef=[0,1], operands=[" +
 //									dermannSeq +
 //								"]}" +
@@ -805,19 +805,19 @@
 		String beg2 = 
 //					"{@type=korap:group, operation=operation:or, operands=[" +
 //						"{@type=korap:group, operation=operation:position, frames=[frame:], sharedClasses=[sharedClasses:intersects], operands=[" +
-//							"{@type=korap:group, operation=operation:class, class=0, operands=[" +
+//							"{@type=korap:group, operation=operation:class, class=1024, operands=[" +
 //								beg1 +
 //							"]}" + "," +
-//							"{@type=korap:group, operation=operation:class, class=0, operands=[" +
+//							"{@type=korap:group, operation=operation:class, class=1024, operands=[" +
 //								kommt +
 //							"]}" +
 //						"], frame=frame:overlaps}," +
-//						"{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+//						"{@type=korap:reference, operation=operation:focus, classRef=[1024], operands=[" +
 //							"{@type=korap:group, operation=operation:sequence, operands=[" +
-//								"{@type=korap:group, operation=operation:class, class=0, operands=[" +
+//								"{@type=korap:group, operation=operation:class, class=1024, operands=[" +
 //									beg1 + 
 //								"]}," +
-//								"{@type=korap:group, operation=operation:class, class=0, operands=[" +
+//								"{@type=korap:group, operation=operation:class, class=1024, operands=[" +
 //									kommt +
 //								"]}" +
 //							"], inOrder=true, distances=[" +
@@ -826,12 +826,12 @@
 //						"]}" +
 //					"]}";
 //		
-						"{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+						"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 							"{@type=korap:group, operation=operation:sequence, operands=[" +
-								"{@type=korap:group, operation=operation:class, class=0, operands=[" +
+								"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 									beg1 + 
 								"]}," +
-								"{@type=korap:group, operation=operation:class, class=0, operands=[" +
+								"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 									kommt +
 								"]}" +
 							"], inOrder=true, distances=[" +
@@ -846,20 +846,20 @@
 		String beg3 = 
 //				"{@type=korap:group, operation=operation:or, operands=[" +
 //						"{@type=korap:group, operation=operation:position, frames=[frame:], sharedClasses=[sharedClasses:intersects], operands=[" +
-//							"{@type=korap:group, operation=operation:class, class=0, operands=[" +
+//							"{@type=korap:group, operation=operation:class, class=1024, operands=[" +
 //								kommt + 
 ////							"," +
 //							"]}," +
-//							"{@type=korap:group, operation=operation:class, class=0, operands=[" +
+//							"{@type=korap:group, operation=operation:class, class=1024, operands=[" +
 //								beg1+
 //							"]}" +
 //						"], frame=frame:overlaps}," +
-//						"{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+//						"{@type=korap:reference, operation=operation:focus, classRef=[1024], operands=[" +
 //							"{@type=korap:group, operation=operation:sequence, operands=[" +
-//								"{@type=korap:group, operation=operation:class, class=0, operands=[" +
+//								"{@type=korap:group, operation=operation:class, class=1024, operands=[" +
 //									kommt +
 //								"]}," +
-//								"{@type=korap:group, operation=operation:class, class=0, operands=[" +
+//								"{@type=korap:group, operation=operation:class, class=1024, operands=[" +
 //									beg1+
 //								"]}" +
 //							"], inOrder=true, distances=[" +
@@ -868,12 +868,12 @@
 //						"]}" +
 //					"]}";
 				
-						"{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+						"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 							"{@type=korap:group, operation=operation:sequence, operands=[" +
-								"{@type=korap:group, operation=operation:class, class=0, operands=[" +
+								"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 									kommt +
 								"]}," +
-								"{@type=korap:group, operation=operation:class, class=0, operands=[" +
+								"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 									beg1+
 								"]}" +
 							"], inOrder=true, distances=[" +
@@ -908,9 +908,9 @@
 		query="Sonne /s0 Mond";   // contains(focus(1:contains({1:<s>},Sonne)),Mond)
 		expected = 
 					"{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
-						"{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
+						"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 							"{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
-								"{@type=korap:group, operation=operation:class, class=1, operands=[" +
+								"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 									"{@type=korap:span, key=s}" +
 								"]}," +
 								"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
@@ -925,9 +925,9 @@
 		query="Sonne /s0,w5 Mond";   
 		expected = 
 					"{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
-						"{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
+						"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 							"{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
-								"{@type=korap:group, operation=operation:class, class=1, operands=[" +
+								"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 									"{@type=korap:span, key=s}" +
 								"]}," +
 								"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
@@ -979,9 +979,9 @@
 		expected = 
 					"{@type=korap:group, operation=operation:or, operands=[" +
 						"{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
-							"{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
+							"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 								"{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
-									"{@type=korap:group, operation=operation:class, class=1, operands=[" +
+									"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 										"{@type=korap:span, key=s}" +
 									"]}," +
 									"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
@@ -1098,16 +1098,34 @@
 	@Test
 	public void testOPNHIT() throws QueryException {
 		query="#NHIT(gehen /w1:10 voran)";
+//		String nhit1 = 
+//				"{@type=korap:reference, operation=operation:focus, classRef=[1025], classRefOp=classRefOp:inversion, operands=[" +
+//					"{@type=korap:group, operation=operation:sequence, " +
+//						"operands=[" +
+//							"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
+//								"{@type=korap:token, wrap={@type=korap:term, key=gehen, layer=orth, match=match:eq}}" +
+//							"]}," +
+//							"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
+//								"{@type=korap:token, wrap={@type=korap:term, key=voran, layer=orth, match=match:eq}}" +
+//							"]}" +
+//						"], inOrder=false, " +
+//						"distances=[" +
+//							"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}" +
+//						"]" +
+//					"}" +
+//				"]}";
+		
 		String nhit1 = 
-				"{@type=korap:reference, operation=operation:focus, classRef=[1], classRefOp=classRefOp:inversion, operands=[" +
+				"{@type=korap:reference, operation=operation:focus, classRef=1025, operands=[" +
 					"{@type=korap:group, operation=operation:sequence, " +
 						"operands=[" +
-							"{@type=korap:group, operation=operation:class, class=1, operands=[" +
-								"{@type=korap:token, wrap={@type=korap:term, key=gehen, layer=orth, match=match:eq}}" +
-							"]}," +
-							"{@type=korap:group, operation=operation:class, class=1, operands=[" +
-								"{@type=korap:token, wrap={@type=korap:term, key=voran, layer=orth, match=match:eq}}" +
-							"]}" +
+							"{@type=korap:token, wrap={@type=korap:term, key=gehen, layer=orth, match=match:eq}}" +
+							"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
+								"{@type=korap:group, operation=operation:repetition, operands=[" +
+									"{@type=korap:token}" +
+								"], boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}}" +
+							"]}," +	
+							"{@type=korap:token, wrap={@type=korap:term, key=voran, layer=orth, match=match:eq}}" +
 						"], inOrder=false, " +
 						"distances=[" +
 							"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}" +
@@ -1123,10 +1141,10 @@
 	public void testOPBED() throws QueryException {
 		query = "#BED(der , sa)";
 		String bed1 = 
-				"{@type=korap:reference, operation=operation:focus, classRef=[1], operands= [" +
+				"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands= [" +
 					"{@type=korap:group, operation=operation:position, frames=[frame:startswith], sharedClasses=[sharedClasses:includes], operands=[" +
 						"{@type=korap:span, key=s}," +
-						"{@type=korap:group, operation=operation:class, class=1, operands=[" +
+						"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 							"{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}" +
 						"]}" +
 					"], frame=frame:startswith}" +
@@ -1137,10 +1155,10 @@
 		
 		query = "#BED(der Mann , +pe)";
 		String bed2 = 
-				"{@type=korap:reference, operation=operation:focus, classRef=[1], operands= [" +
+				"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands= [" +
 						"{@type=korap:group, operation=operation:position, frames=[frame:endswith], sharedClasses=[sharedClasses:includes], operands=[" +
 							"{@type=korap:span, key=p}," +
-							"{@type=korap:group, operation=operation:class, class=1, operands=[" +
+							"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 								"{@type=korap:group, operation=operation:sequence, operands=[" +
 									"{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
 									"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
@@ -1154,11 +1172,11 @@
 		
 		query = "#BED(der Mann , sa,-pa)";
 		String bed3 = 
-				"{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
-					"{@type=korap:group, operation=operation:sequence, operands=[" +
+				"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
+					"{@type=korap:group, operation=operation:position, frames=[frame:matches], sharedClasses=[sharedClasses:equals], operands=[" +
 						"{@type=korap:group, operation=operation:position, frames=[frame:startswith], sharedClasses=[sharedClasses:includes], operands=[" +
 							"{@type=korap:span, key=s}," +
-							"{@type=korap:group, operation=operation:class, class=1, operands=[" +
+							"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 								"{@type=korap:group, operation=operation:sequence, operands=[" +
 									"{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
 									"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
@@ -1167,16 +1185,14 @@
 						"], frame=frame:startswith}," +
 						"{@type=korap:group, operation=operation:position, frames=[frame:startswith], sharedClasses=[sharedClasses:includes], operands=[" +
 							"{@type=korap:span, key=p}," +
-							"{@type=korap:group, operation=operation:class, class=2, operands=[" +
+							"{@type=korap:group, operation=operation:class, class=1026, operands=[" +
 								"{@type=korap:group, operation=operation:sequence, operands=[" +
 									"{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
 									"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
 								"]}" +
 							"]}" +
 						"], frame=frame:startswith, exclude=true}" +
-					"], distances=[" +
-						"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=0}, min=0, max=0}" +
-					"]}" +
+					"], frame=frame:matches}" +
 				"]}";
 		ct = new CosmasTree(query);
 		map = ct.getRequestMap().get("query").toString();
@@ -1188,10 +1204,10 @@
 		
 		query = "Der:sa";
 		String col1 = 
-				"{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
+				"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
 					"{@type=korap:group, operation=operation:position, frames=[frame:startswith], sharedClasses=[sharedClasses:includes], operands=[" +
 						"{@type=korap:span, key=s}," +
-						"{@type=korap:group, operation=operation:class, class=1, operands=[" +
+						"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 							"{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}" +
 						"]}" +
 					"], frame=frame:startswith}" +
@@ -1202,29 +1218,27 @@
 		
 		query = "Mann:sa,-pa,+te)";
 		String col2 = 
-				"{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
-					"{@type=korap:group, operation=operation:sequence, operands=[" +
+				"{@type=korap:reference, operation=operation:focus, classRef=[1025], operands=[" +
+					"{@type=korap:group, operation=operation:position, frames=[frame:matches], sharedClasses=[sharedClasses:equals], operands=[" +
 						"{@type=korap:group, operation=operation:position, frames=[frame:startswith], sharedClasses=[sharedClasses:includes], operands=[" +
 							"{@type=korap:span, key=s}," +
-							"{@type=korap:group, operation=operation:class, class=1, operands=[" +
+							"{@type=korap:group, operation=operation:class, class=1025, operands=[" +
 									"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
 							"]}" +
 						"], frame=frame:startswith}," +
 						"{@type=korap:group, operation=operation:position, frames=[frame:startswith], sharedClasses=[sharedClasses:includes], operands=[" +
 							"{@type=korap:span, key=p}," +
-							"{@type=korap:group, operation=operation:class, class=2, operands=[" +
+							"{@type=korap:group, operation=operation:class, class=1026, operands=[" +
 									"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
 							"]}" +
 						"], frame=frame:startswith, exclude=true}," +
 						"{@type=korap:group, operation=operation:position, frames=[frame:endswith], sharedClasses=[sharedClasses:includes], operands=[" +
 							"{@type=korap:span, key=t}," +
-							"{@type=korap:group, operation=operation:class, class=3, operands=[" +
+							"{@type=korap:group, operation=operation:class, class=1027, operands=[" +
 									"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
 							"]}" +
 						"], frame=frame:endswith}" +
-					"], distances=[" +
-						"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=0}, min=0, max=0}" +
-					"]}" +
+					"], frame=frame:matches}" +
 				"]}";
 		ct = new CosmasTree(query);
 		map = ct.getRequestMap().get("query").toString();
diff --git a/src/test/java/PoliqarpPlusTreeTest.java b/src/test/java/PoliqarpPlusTreeTest.java
index 0208a5d..53145d8 100644
--- a/src/test/java/PoliqarpPlusTreeTest.java
+++ b/src/test/java/PoliqarpPlusTreeTest.java
@@ -400,6 +400,35 @@
 	}
 
 	@Test
+	public void testDistancesWithClass() throws QueryException {
+		query = "[base=der]{1:[]}[base=Mann]";
+		expected = 
+				"{@type=korap:group, operation=operation:sequence, operands=[" +
+					"{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
+					"{@type=korap:group, operation=operation:class, class=1, operands=[" +
+						"{@type=korap:token}" +
+					"]}," +
+					"{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
+				"]}";
+		ppt = new PoliqarpPlusTree(query);
+		map = ppt.getRequestMap().get("query").toString();
+		assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
+		
+		query = "{1:[]}[base=der][base=Mann]";
+		expected = 
+				"{@type=korap:group, operation=operation:sequence, operands=[" +
+					"{@type=korap:group, operation=operation:class, class=1, operands=[" +
+						"{@type=korap:token}" +
+					"]}," +
+					"{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
+					"{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
+				"]}";
+		ppt = new PoliqarpPlusTree(query);
+		map = ppt.getRequestMap().get("query").toString();
+		assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
+	}
+	
+	@Test
 	public void testLeadingTrailingEmptyTokens() throws QueryException {
 		// startswith(<s>, [][base=Mann]
 		String et1 =