- system-set classes start at 128
- positions debug
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 0a348fa..7510710 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
@@ -147,49 +147,48 @@
 		return group;
 	}
 	
-	protected LinkedHashMap<String, Object> makePosition(String[] allowedFrames, String[] sharedClasses) {
+	protected LinkedHashMap<String, Object> makePosition(String[] allowedFrames, String[] classRefCheck) {
 		LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
 		group.put("@type", "korap:group");
 		group.put("operation", "operation:position");
 		group.put("frames", Arrays.asList(allowedFrames));
-//		group.put("sharedClasses", Arrays.asList(sharedClasses));
 		group.put("operands", new ArrayList<Object>());
 		// DEPRECATED 'frame'
-		if (sharedClasses.length==0) sharedClasses = new String[]{"classRefCheck:includes"};
+		if (classRefCheck.length==0) classRefCheck = new String[]{"classRefCheck:includes"};
 		String frame = "";
 		
-		if (allowedFrames.length==0 && sharedClasses[0]=="classRefCheck:includes") {
+		if (allowedFrames.length==0 && classRefCheck[0]=="classRefCheck:includes") {
 			frame = "frame:contains";
-		} else if (allowedFrames.length==0 && sharedClasses[0]=="classRefCheck:intersects") {
+		} else if (allowedFrames.length==0 && classRefCheck[0]=="classRefCheck:intersects") {
 			frame = "frame:overlaps";
-		} else if (allowedFrames[0]=="frames:startswith" && sharedClasses[0]=="classRefCheck:includes") {
+		} else if (allowedFrames[0]=="frames:startswith" && classRefCheck[0]=="classRefCheck:includes") {
 			frame = "frame:startswith";
-		} else if (allowedFrames[0]=="frames:endswith" && sharedClasses[0]=="classRefCheck:includes") {
+		} else if (allowedFrames[0]=="frames:endswith" && classRefCheck[0]=="classRefCheck:includes") {
 			frame = "frame:endswith";
-		} else if (allowedFrames[0]=="frames:matches" && sharedClasses[0]=="classRefCheck:includes" && sharedClasses.length==1) {
-			frame = "frame:endswith";
-		} else if (allowedFrames[0]=="frames:matches" && sharedClasses[0]=="classRefCheck:includes" && sharedClasses[1]=="classRefCheck:unequals") {
+		} else if (allowedFrames[0]=="frames:matches" && classRefCheck[0]=="classRefCheck:includes" && classRefCheck.length==1) {
 			frame = "frame:matches";
-		} else if (allowedFrames[0]=="frames:matches" && sharedClasses[0]=="classRefCheck:equals") {
+		} else if (allowedFrames[0]=="frames:matches" && classRefCheck[0]=="classRefCheck:includes" && classRefCheck[1]=="classRefCheck:unequals") {
+			frame = "frame:matches";
+		} else if (allowedFrames[0]=="frames:matches" && classRefCheck[0]=="classRefCheck:equals") {
 			frame = "frame:matches";			
-		} else if (allowedFrames[0]=="frames:contains" && sharedClasses[0]=="classRefCheck:includes") {
+		} else if (allowedFrames[0]=="frames:contains" && classRefCheck[0]=="classRefCheck:includes") {
 			frame = "frame:contains";
-		} else if (allowedFrames[0]=="frames:startswith" && sharedClasses[0]=="classRefCheck:intersects") {
+		} else if (allowedFrames[0]=="frames:startswith" && classRefCheck[0]=="classRefCheck:intersects") {
 			frame = "frame:overlapsLeft";
-		} else if (allowedFrames[0]=="frames:endswith" && sharedClasses[0]=="classRefCheck:intersects") {
+		} else if (allowedFrames[0]=="frames:endswith" && classRefCheck[0]=="classRefCheck:intersects") {
 			frame = "frame:overlapsRight";
-		} else if (allowedFrames[0]=="frames:matches" && sharedClasses[0]=="classRefCheck:intersects") {
+		} else if (allowedFrames[0]=="frames:matches" && classRefCheck[0]=="classRefCheck:intersects") {
 			frame = "frame:matches";
-		} else if (allowedFrames[0]=="frames:matches" && sharedClasses[0]=="classRefCheck:unequals") {
+		} else if (allowedFrames[0]=="frames:matches" && classRefCheck[0]=="classRefCheck:unequals") {
 			frame = "frame:matches";
-		} else if (allowedFrames[0]=="frames:matches" && sharedClasses[0]=="classRefCheck:equals") {
+		} else if (allowedFrames[0]=="frames:matches" && classRefCheck[0]=="classRefCheck:equals") {
 			frame = "frame:matches";
-		} else if (allowedFrames[0]=="frames:contains" && sharedClasses[0]=="classRefCheck:intersects") {
+		} else if (allowedFrames[0]=="frames:contains" && classRefCheck[0]=="classRefCheck:intersects") {
 			frame = "frame:contains";
 		}
 		group.put("frame", frame);
 		announcements.add("Deprecated 2014-09-22: 'frame' only to be supported until 3 months from deprecation date. " +
-				"Position frames are now expressed through 'frames' and 'sharedClasses'.");
+				"Position frames are now expressed through 'frames'.");
 		return group;
 	}
 	
@@ -202,10 +201,10 @@
 		group.put("@type", "korap:group");
 		group.put("operation", "operation:class");
 		if (setBySystem) {
-			group.put("class", 1024+classCount);
-			group.put("classOut", 1024+classCount);
+			group.put("class", 128+classCount);
+			group.put("classOut", 128+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 "+(1024+classCount));
+					"your query for later reference to a part of the query. The class id is "+(128+classCount));
 		} else {
 			group.put("class", classCount);
 			group.put("classOut", classCount);
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/AqlTree.java b/src/main/java/de/ids_mannheim/korap/query/serialize/AqlTree.java
index 747b52f..ad2d5b7 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/AqlTree.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/AqlTree.java
@@ -520,36 +520,31 @@
 //			relation.put("groupType", "position");
 			String reltype = operatorNode.getChild(0).toStringTree(parser);
 			String[] frames = new String[]{};
-			String[] sharedClasses = new String[]{"sharedClasses:includes"};
 			switch (reltype) {
 			case "_=_":
-				frames = new String[]{"frame:matches"}; 
-				sharedClasses = new String[]{"sharedClasses:equals"};
+				frames = new String[]{"frames:matches"}; 
 				break;
 			case "_l_":
-				frames = new String[]{"frame:startswith"};
+				frames = new String[]{"frames:startswith"};
 				break;
 			case "_r_":
-				frames = new String[]{"frame:endswith"};
+				frames = new String[]{"frames:endswith"};
 				break;
 			case "_i_":
-				frames = new String[]{"frame:contains"};break;
+				frames = new String[]{"frames:contains"};break;
 			case "_o_":
-				frames = new String[]{"frame:overlapsLeft", "frame:overlapsRight"};
-				sharedClasses = new String[]{"sharedClasses:intersects"};
+				frames = new String[]{"frames:overlapsLeft", "frames:overlapsRight"};
 				break;
 			case "_ol_":
-				frames = new String[]{"frame:overlapsLeft"};
-				sharedClasses = new String[]{"sharedClasses:intersects"};
+				frames = new String[]{"frames:overlapsLeft"};
 				break;
 			case "_or_":
-				frames = new String[]{"frame:overlapsRight"};
-				sharedClasses = new String[]{"sharedClasses:intersects"};
+				frames = new String[]{"frames:overlapsRight"};
 				break;
 			}
 //			relation.put("frames", frames);
 //			relation.put("sharedClasses", sharedClasses);
-			relation = makePosition(frames, sharedClasses);
+			relation = makePosition(frames, new String[]{});
 			relation.put("groupType", "position");
 		}
 		else if (operator.equals("identity")) {
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 f8a7f19..78cf472 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
@@ -225,6 +225,7 @@
 			LinkedHashMap<String, Object> token = new LinkedHashMap<String, Object>();
 			token.put("@type", "korap:token");
 			ArrayList<Object> terms = new ArrayList<Object>();
+			LinkedHashMap<String, Object> fieldMap = null;
 			for (String morphterm : morphterms) {
 				String[] attrval = morphterm.split("=");
 				if (attrval[0].endsWith("!")) {
@@ -232,7 +233,7 @@
 					attrval[0] = attrval[0].replace("!", "");
 				}
 				String[] foundrylayer = attrval[0].split("/");
-				LinkedHashMap<String, Object> fieldMap = new LinkedHashMap<String, Object>();
+				fieldMap = new LinkedHashMap<String, Object>();
 				fieldMap.put("@type", "korap:term");
 				//     			fieldMap.put("key", "morph:"+node.getChild(0).toString().replace(" ", "_"));
 				fieldMap.put("key", attrval[1]);
@@ -253,7 +254,7 @@
 				terms.add(fieldMap);
 			}
 			if (morphterms.length == 1) {
-				token.put("wrap", terms);
+				token.put("wrap", fieldMap);
 			} else {
 				LinkedHashMap<String, Object> termGroup = makeTermGroup("and");
 				termGroup.put("operands", terms);
@@ -450,7 +451,7 @@
 			if (! (openNodeCats.get(1).equals("OPBEG") || openNodeCats.get(1).equals("OPEND") || inOPALL || openNodeCats.get(1).equals("OPNHIT"))) {
 				wrapOperandInClass(node,1,classCounter);
 				wrapOperandInClass(node,2,classCounter);
-				group = wrapInReference(group, 1024+classCounter++);
+				group = wrapInReference(group, 128+classCounter++);
 			} else if (openNodeCats.get(1).equals("OPNHIT")) {
 				LinkedHashMap<String,Object> repetition = makeRepetition(min, max);
 				((ArrayList<Object>) repetition.get("operands")).add(makeToken());
@@ -519,15 +520,15 @@
 			stackedObjects++;
 			// Step II: wrap in reference and decide where to put
 			ArrayList<String> check = (ArrayList<String>) positionOptions.get("classRefCheck");
-			Integer[] classIn = new Integer[]{1024+classCounter-2,1024+classCounter-1};
-			LinkedHashMap<String, Object> classRefCheck = makeClassRefCheck(check, classIn, 1024+classCounter);
+			Integer[] classIn = new Integer[]{128+classCounter-2,128+classCounter-1};
+			LinkedHashMap<String, Object> classRefCheck = makeClassRefCheck(check, classIn, 128+classCounter);
 			((ArrayList<Object>) classRefCheck.get("operands")).add(posgroup);
 			LinkedHashMap<String, Object> focusGroup = null;
 			if ((boolean) positionOptions.get("matchall") == true) {
 				focusGroup = makeResetReference();
 				((ArrayList<Object>) focusGroup.get("operands")).add(classRefCheck);
 			} else { // match only first argument
-				focusGroup = wrapInReference(classRefCheck, 1024+classCounter-1);
+				focusGroup = wrapInReference(classRefCheck, 128+classCounter-1);
 			}
 			putIntoSuperObject(focusGroup, 1);
 		}
@@ -556,10 +557,10 @@
 		}
 
 		if (nodeCat.equals("OPNHIT")) {
-			Integer[] classRef = new Integer[]{1024+classCounter+1, 1024+classCounter+2}; 
+			Integer[] classRef = new Integer[]{128+classCounter+1, 128+classCounter+2}; 
 			//            classRef.add(classCounter + 1);  // yes, do this twice (two classes)!
-			LinkedHashMap<String, Object> group = makeReference(1024+classCounter);
-			LinkedHashMap<String, Object> classRefCheck = makeClassRefOp("classRefOp:inversion", classRef, classCounter+1024);
+			LinkedHashMap<String, Object> group = makeReference(128+classCounter);
+			LinkedHashMap<String, Object> classRefCheck = makeClassRefOp("classRefOp:inversion", classRef, classCounter+128);
 			ArrayList<Object> operands = new ArrayList<Object>();
 			operands.add(classRefCheck);
 			group.put("operands", operands);
@@ -601,7 +602,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(1024+classCounter);
+			LinkedHashMap<String, Object> submatchgroup = makeReference(128+classCounter);
 			ArrayList<Object> submatchoperands = new ArrayList<Object>();
 			submatchgroup.put("operands", submatchoperands);
 			putIntoSuperObject(submatchgroup);
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 bb78e03..5418c09 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
@@ -20,7 +20,7 @@
 public class PoliqarpPlusTree extends Antlr4AbstractSyntaxTree {
 
 	private static Logger log = LoggerFactory.getLogger(PoliqarpPlusTree.class);
-	private int classCounter = 1024;
+	private int classCounter = 128;
 
 	/**
 	 * Most centrally, this class maintains a set of nested maps and lists which represent the JSON tree, which is built by the JSON serialiser