Performance improvements
diff --git a/src/test/java/de/ids_mannheim/korap/benchmark/TestBenchmarkElementSpans.java b/src/test/java/de/ids_mannheim/korap/benchmark/TestBenchmarkElementSpans.java
index 39c3c2a..cdaf9fe 100644
--- a/src/test/java/de/ids_mannheim/korap/benchmark/TestBenchmarkElementSpans.java
+++ b/src/test/java/de/ids_mannheim/korap/benchmark/TestBenchmarkElementSpans.java
@@ -26,7 +26,7 @@
 public class TestBenchmarkElementSpans {
 
     @Test
-    public void checkspans1 () throws IOException {
+    public void checkBenchmark1 () throws IOException {
 	Properties prop = new Properties();
 	InputStream fr = new FileInputStream(getClass().getResource("/korap.conf").getFile());
 	prop.load(fr);
@@ -37,70 +37,162 @@
 	// Create a container for virtual collections:
 	KorapCollection kc = new KorapCollection(ki);
 
-	// Construct filter generator
-	// KorapFilter kf = new KorapFilter();
-
-	// The virtual collection consists of all documents that have
-	// the textClasses "reisen" and "freizeit"
-	//	kc.filter( kf.and("textClass", "reisen").and("textClass", "freizeit-unterhaltung") );
-
-	// This is real slow atm - sorry
-	// kc.filter(kf.and("textClass", "kultur"));
-
-
-	// Create a query
-	// KorapQuery kq = new KorapQuery("tokens");
-
 	long t1 = 0, t2 = 0;
+	/// cosmas20.json!!!
+	String json = getString(getClass().getResource("/queries/benchmark1.jsonld").getFile());
+
+	int rounds = 1000;
+
+	KorapResult kr = new KorapResult();
+
 	t1 = System.nanoTime();
-
-	String json = getString(getClass().getResource("/queries/bsp19.jsonld").getFile());
-
-	int rounds = 1;
-
 	for (int i = 1; i <= rounds; i++) {
-	    /*
-	    SpanQuery query =
-		kq.within(
-			  kq.tag("xip/const:NPA"),
-			  kq._(1,
-			       kq.seq(
-				      kq._(2, kq.seg("cnx/p:A").with("mate/m:number:sg"))
-				      ).append(
-					       kq.seg("opennlp/p:NN").with("tt/p:NN")
-					       )
-			       )
-			  ).toQuery();
-	    */
-	    // SpanQuery query = kq.tag("s").toQuery();
-
-	    KorapResult kr = new KorapSearch(json).run(ki);
-	    System.err.println(kr.toJSON());
+	    kr = new KorapSearch(json).run(ki);
 	};
-
 	t2 = System.nanoTime();
 
+	assertEquals("TotalResults", 30751, kr.getTotalResults());
+
+	// System.err.println(kr.toJSON());
+
+
 	//	long seconds = (long) (t2 - t1 / 1000) % 60 ;
 	double seconds = (double)(t2-t1) / 1000000000.0;
 	
 	System.out.println("It took " + seconds + " seconds");
 
+	// 100 times:
+	// 43,538 sec
+	// 4.874
 
-	//	kc = new KorapCollection("{\"meta\":[{\"@type\":\"korap:meta-filter\",\"@value\":{\"@type\":\"korap:term\",\"@field\":\"korap:field#corpusID\",\"@value\":\"A00\"}},{\"@type\":\"korap:meta-extend\",\"@value\":{\"@type\":\"korap:term\",\"@field\":\"korap:field#corpusID\",\"@value\":\"A01\"}}]}");
-
-	//	kc = new KorapCollection("{\"meta\":[{\"@type\":\"korap:meta-filter\",\"@value\":{\"@type\":\"korap:term\",\"@field\":\"korap:field#corpusID\",\"@value\":\"A01\"}}]}");
-	/*
-	kc = new KorapCollection("{\"meta\":[{\"@type\":\"korap:meta-filter\",\"@value\":{\"@type\":\"korap:term\",\"@field\":\"korap:field#textClass\",\"@value\":\"reisen\"}}]}");
-	kc.setIndex(ki);
-
-	System.err.println(kc.getFilter(0).toString());
-	System.err.println(kc.numberOf("documents"));
-
-	*/
-
-	// assertEquals(14, kc.numberOf("documents"));
+	// 1000 times:
+	// 36.613 sec
     };
 
+
+    @Test
+    public void checkBenchmark2JSON () throws IOException {
+	Properties prop = new Properties();
+	InputStream fr = new FileInputStream(getClass().getResource("/korap.conf").getFile());
+	prop.load(fr);
+
+	// Get the real index
+	KorapIndex ki = new KorapIndex(new MMapDirectory(new File(prop.getProperty("lucene.indexDir"))));
+
+	// Create a container for virtual collections:
+	KorapCollection kc = new KorapCollection(ki);
+
+	long t1 = 0, t2 = 0;
+	/// cosmas20.json!!!
+	String json = getString(getClass().getResource("/queries/benchmark2.jsonld").getFile());
+
+	int rounds = 10000;
+
+	KorapResult kr = new KorapResult();
+	String result = new String("");
+
+	t1 = System.nanoTime();
+	double length = 0;
+	for (int i = 1; i <= rounds; i++) {
+	    kr = new KorapSearch(json).run(ki);
+	    length += kr.toJSON().length();
+	};
+	t2 = System.nanoTime();
+
+	//	assertEquals("TotalResults", 30751, kr.getTotalResults());
+
+	// System.err.println(kr.toJSON());
+
+	//	long seconds = (long) (t2 - t1 / 1000) % 60 ;
+	double seconds = (double)(t2-t1) / 1000000000.0;
+	
+	System.out.println("It took " + seconds + " seconds");
+
+	// 10000 times:
+	//  77.167124985 sec
+    };
+
+    @Test
+    public void checkBenchmarkIndexDocuments () throws IOException {
+	long t1 = 0, t2 = 0;
+
+	int rounds = 10;
+
+	ArrayList<String> docs = new ArrayList<String>(700);
+
+	for (int a = 0; a < 50; a++) {
+	    for (String d : new String[] {"00001", "00002", "00003",
+				   "00004", "00005", "00006", "02439"}) {
+		docs.add(d);
+	    };
+	};
+
+	t1 = System.nanoTime();
+	double length = 0;
+	for (int i = 1; i <= rounds; i++) {
+	    // Construct index
+	    KorapIndex ki = new KorapIndex();
+
+	    // Indexing test files
+	    for (String d : docs) {
+		FieldDocument fd = ki.addDocFile(
+		    getClass().getResource("/wiki/" + d + ".json.gz").getFile(),
+		    true
+		);
+	    };
+	    ki.commit();
+	};
+	t2 = System.nanoTime();
+
+	double seconds = (double)(t2-t1) / 1000000000.0;
+	System.out.println("It took " + seconds + " seconds");
+
+	// 10 times / 350 docs:
+	// 36.26158006 seconds
+	// 32.52575097 seconds
+    };
+
+
+    @Test
+    public void checkBenchmark3 () throws IOException {
+	Properties prop = new Properties();
+	InputStream fr = new FileInputStream(getClass().getResource("/korap.conf").getFile());
+	prop.load(fr);
+
+	// Get the real index
+	KorapIndex ki = new KorapIndex(new MMapDirectory(new File(prop.getProperty("lucene.indexDir"))));
+
+	// Create a container for virtual collections:
+	KorapCollection kc = new KorapCollection(ki);
+
+	long t1 = 0, t2 = 0;
+	/// cosmas20.json!!!
+	String json = getString(getClass().getResource("/queries/benchmark3.jsonld").getFile());
+
+	int rounds = 500;
+
+	KorapResult kr = new KorapResult();
+
+	t1 = System.nanoTime();
+	for (int i = 1; i <= rounds; i++) {
+	    kr = new KorapSearch(json).run(ki);
+	};
+	t2 = System.nanoTime();
+
+	assertEquals("TotalResults", 70229, kr.getTotalResults());
+
+	// System.err.println(kr.toJSON());
+
+	//	long seconds = (long) (t2 - t1 / 1000) % 60 ;
+	double seconds = (double)(t2-t1) / 1000000000.0;
+	
+	System.out.println("It took " + seconds + " seconds");
+
+	// 500 times:
+	// 71.715862716 seconds
+    };
+
+
     public static String getString (String path) {
 	StringBuilder contentBuilder = new StringBuilder();
 	try {
diff --git a/src/test/resources/queries/benchmark1.jsonld b/src/test/resources/queries/benchmark1.jsonld
new file mode 100644
index 0000000..79403b4
--- /dev/null
+++ b/src/test/resources/queries/benchmark1.jsonld
@@ -0,0 +1,25 @@
+{
+    "@context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+    "query": {
+	"@type": "korap:group", 
+	"operation": "operation:position", 
+	"frame": "frame:contains",
+	"operands": [
+	    {
+		"@type": "korap:span",
+		"layer" : "c",
+		"foundry" : "cnx",
+		"key": "np"
+	    }, 
+	    {
+		"@type": "korap:token",
+		"wrap" : {
+		    "@type": "korap:term", 
+		    "foundry": "mate",
+		    "layer": "pos",
+		    "key" : "NE"
+		}
+	    }
+	]
+    }
+}
diff --git a/src/test/resources/queries/benchmark2.jsonld b/src/test/resources/queries/benchmark2.jsonld
new file mode 100644
index 0000000..81c1016
--- /dev/null
+++ b/src/test/resources/queries/benchmark2.jsonld
@@ -0,0 +1,20 @@
+{
+    "@context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+    "query": {
+	"@type": "korap:token", 
+	"wrap" : {
+	    "@type": "korap:term", 
+	    "layer": "orth",
+	    "key" : "Buchstabe"
+	}
+    },
+    "meta" : {
+	"count": 100,
+	"cutOff": false,
+	"context":{
+	    "left": [ "token", 10 ],
+	    "right": [ "token", 10 ]
+	},
+	"startPage": 1
+    }
+}
diff --git a/src/test/resources/queries/benchmark3.jsonld b/src/test/resources/queries/benchmark3.jsonld
new file mode 100644
index 0000000..36acfe9
--- /dev/null
+++ b/src/test/resources/queries/benchmark3.jsonld
@@ -0,0 +1,27 @@
+{
+    "@context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+    "query": {
+	"@type": "korap:group", 
+	"operation": "operation:sequence",
+	"operands": [
+	    {
+		"@type": "korap:token",
+		"wrap" : {
+		    "@type": "korap:term", 
+		    "foundry": "mate",
+		    "layer": "pos",
+		    "key" : "ADJA"
+		}
+	    },
+	    {
+		"@type": "korap:token",
+		"wrap" : {
+		    "@type": "korap:term", 
+		    "foundry": "mate",
+		    "layer": "pos",
+		    "key" : "NE"
+		}
+	    }
+	]
+    }
+}
diff --git a/src/test/resources/queries/bsp1.jsonld b/src/test/resources/queries/bsp1.jsonld
index 36fb042..5361a5c 100644
--- a/src/test/resources/queries/bsp1.jsonld
+++ b/src/test/resources/queries/bsp1.jsonld
@@ -1,146 +1,46 @@
 {
-  "@context" : {
-    "korap" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/",
-    "query" : "korap:query",
-    "meta" : "korap:meta",
-    "collections" : {
-      "@id" : "korap:collections",
-      "@container" : "@list"
-    },
-    "token" : "korap:token/",
-    "distance" : "korap:distance/",
-    "boundary" : "korap:boundary/",
-    "group" : "korap:group/",
-    "span" : "korap:span/",
-    "term" : "korap:term/",
-    "termGroup" : "korap:termGroup/",
-    "wrap" : "token:wrap",
-    "operation" : {
-      "@id" : "group:operation/",
-      "@type" : "@id"
-    },
-    "class" : {
-      "@id" : "group:class",
-      "@type" : "xsd:integer"
-    },
-    "operands" : {
-      "@id" : "group:operands",
-      "@container" : "@list"
-    },
-    "frame" : {
-      "@id" : "group:frame/",
-      "@type" : "@id"
-    },
-    "classRef" : {
-      "@id" : "group:classRef",
-      "@type" : "xsd:integer"
-    },
-    "spanRef" : {
-      "@id" : "group:spanRef",
-      "@type" : "xsd:integer"
-    },
-    "classRefOp" : {
-      "@id" : "group:classRefOp",
-      "@type" : "@id"
-    },
-    "min" : {
-      "@id" : "boundary:min",
-      "@type" : "xsd:integer"
-    },
-    "max" : {
-      "@id" : "boundary:max",
-      "@type" : "xsd:integer"
-    },
-    "exclude" : {
-      "@id" : "group:exclude",
-      "@type" : "xsd:boolean"
-    },
-    "distances" : {
-      "@id" : "group:distances",
-      "@container" : "@list"
-    },
-    "inOrder" : {
-      "@id" : "group:inOrder",
-      "@type" : "xsd:boolean"
-    },
-    "exclude" : {
-      "@id" : "group:exclude",
-      "@type" : "xsd:boolean"
-    },
-    "key" : {
-      "@id" : "korap:key",
-      "@type" : "xsd:string"
-    },
-    "foundry" : {
-      "@id" : "korap:foundry",
-      "@type" : "xsd:string"
-    },
-    "layer" : {
-      "@id" : "korap:layer",
-      "@type" : "xsd:string"
-    },
-    "value" : {
-      "@id" : "korap:value",
-      "@type" : "xsd:string"
-    },
-    "caseInsensitive" : {
-      "@id" : "term:caseInsensitive",
-      "@type" : "xsd:boolean"
-    },
-    "type" : {
-      "@id" : "term:type/",
-      "@type" : "@id"
-    },
-    "match" : {
-      "@id" : "term:match/",
-      "@type" : "@id"
-    },
-    "relation" : {
-      "@id" : "korap:relation/",
-      "@type" : "@id"
+    "@context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+    "query": {
+	"@type": "korap:group", 
+	"operation": "operation:or",
+	"operands": [
+	    {
+		"@type": "korap:token", 
+		"wrap": {
+		    "@type": "korap:term", 
+		    "layer": "base",
+		    "key": "foo"
+		}
+	    }, 
+	    {
+		"@type": "korap:group", 
+		"min" : 0,
+		"operation": "operation:repetition",
+		"operands": [
+		    {
+			"@type": "korap:group", 
+			"operation" : "operation:sequence",
+			"operands": [
+			    {
+				"@type": "korap:token", 
+				"wrap": {
+				    "@type": "korap:term", 
+				    "key": "foo", 
+				    "layer" : "base"
+				}
+			    }, 
+			    {
+				"@type": "korap:token", 
+				"wrap": {
+				    "@type": "korap:term",
+				    "layer": "base",
+				    "key" : "bar"
+				}
+			    }
+			]
+		    }
+		]
+	    }
+	]
     }
-  },
-  "query": {
-    "@type": "korap:group", 
-    "operation": "operation:or",
-    "operands": [
-      {
-        "@type": "korap:token", 
-        "wrap": {
-          "@type": "korap:term", 
-	  "layer": "base",
-          "key": "foo"
-        }
-      }, 
-      {
-        "@type": "korap:group", 
-	"min" : 0,
-        "operation": "operation:repetition",
-        "operands": [
-          {
-            "@type": "korap:group", 
-            "operation" : "operation:sequence",
-            "operands": [
-              {
-                "@type": "korap:token", 
-                "wrap": {
-                  "@type": "korap:term", 
-                  "key": "foo", 
-                  "layer" : "base"
-                }
-              }, 
-              {
-                "@type": "korap:token", 
-                "wrap": {
-                  "@type": "korap:term",
-                  "layer": "base",
-                  "key" : "bar"
-                }
-              }
-            ]
-          }
-        ]
-      }
-    ]
-  }
-}
\ No newline at end of file
+}
diff --git a/src/test/resources/queries/bsp19.jsonld b/src/test/resources/queries/bsp19.jsonld
index 5145e9f..1e12ed9 100644
--- a/src/test/resources/queries/bsp19.jsonld
+++ b/src/test/resources/queries/bsp19.jsonld
@@ -39,7 +39,7 @@
     },
     "meta" : {
 	"count": 25,
-	"cutOff": true,
+	"cutOff": false,
 	"context":{
 	    "left": [ "char", 110 ],
 	    "right": [ "char", 110 ]
diff --git a/src/test/resources/queries/bsp2.jsonld b/src/test/resources/queries/bsp2.jsonld
index 08ac500..9a3a076 100644
--- a/src/test/resources/queries/bsp2.jsonld
+++ b/src/test/resources/queries/bsp2.jsonld
@@ -1,142 +1,42 @@
 {
-  "@context" : {
-    "korap" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/",
-    "query" : "korap:query",
-    "meta" : "korap:meta",
-    "collections" : {
-      "@id" : "korap:collections",
-      "@container" : "@list"
-    },
-    "token" : "korap:token/",
-    "distance" : "korap:distance/",
-    "boundary" : "korap:boundary/",
-    "group" : "korap:group/",
-    "span" : "korap:span/",
-    "term" : "korap:term/",
-    "termGroup" : "korap:termGroup/",
-    "wrap" : "token:wrap",
-    "operation" : {
-      "@id" : "group:operation/",
-      "@type" : "@id"
-    },
-    "class" : {
-      "@id" : "group:class",
-      "@type" : "xsd:integer"
-    },
-    "operands" : {
-      "@id" : "group:operands",
-      "@container" : "@list"
-    },
-    "frame" : {
-      "@id" : "group:frame/",
-      "@type" : "@id"
-    },
-    "classRef" : {
-      "@id" : "group:classRef",
-      "@type" : "xsd:integer"
-    },
-    "spanRef" : {
-      "@id" : "group:spanRef",
-      "@type" : "xsd:integer"
-    },
-    "classRefOp" : {
-      "@id" : "group:classRefOp",
-      "@type" : "@id"
-    },
-    "min" : {
-      "@id" : "boundary:min",
-      "@type" : "xsd:integer"
-    },
-    "max" : {
-      "@id" : "boundary:max",
-      "@type" : "xsd:integer"
-    },
-    "exclude" : {
-      "@id" : "group:exclude",
-      "@type" : "xsd:boolean"
-    },
-    "distances" : {
-      "@id" : "group:distances",
-      "@container" : "@list"
-    },
-    "inOrder" : {
-      "@id" : "group:inOrder",
-      "@type" : "xsd:boolean"
-    },
-    "exclude" : {
-      "@id" : "group:exclude",
-      "@type" : "xsd:boolean"
-    },
-    "key" : {
-      "@id" : "korap:key",
-      "@type" : "xsd:string"
-    },
-    "foundry" : {
-      "@id" : "korap:foundry",
-      "@type" : "xsd:string"
-    },
-    "layer" : {
-      "@id" : "korap:layer",
-      "@type" : "xsd:string"
-    },
-    "value" : {
-      "@id" : "korap:value",
-      "@type" : "xsd:string"
-    },
-    "caseInsensitive" : {
-      "@id" : "term:caseInsensitive",
-      "@type" : "xsd:boolean"
-    },
-    "type" : {
-      "@id" : "term:type/",
-      "@type" : "@id"
-    },
-    "match" : {
-      "@id" : "term:match/",
-      "@type" : "@id"
-    },
-    "relation" : {
-      "@id" : "korap:relation/",
-      "@type" : "@id"
+    "@context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+    "query": {
+	"@type": "korap:group", 
+	"operation" : "operation:sequence",
+	"operands": [
+	    {
+		"@type": "korap:group", 
+		"operation": "operation:or",
+		"operands": [
+		    {
+			"@type": "korap:token", 
+			"wrap": {
+			    "@type": "korap:term", 
+			    "foundry": "mate", 
+			    "layer": "lemma", 
+			    "key" : "foo"
+			}
+		    }, 
+		    {
+			"@type": "korap:token", 
+			"wrap": {
+			    "@type": "korap:term", 
+			    "foundry": "mate", 
+			    "layer": "lemma",
+			    "key" : "bar"
+			}
+		    }
+		]
+	    }, 
+	    {
+		"@type": "korap:token", 
+		"wrap": {
+		    "@type": "korap:term", 
+		    "foundry": "mate", 
+		    "layer": "lemma",
+		    "key" : "foobar"
+		}
+	    }
+	]
     }
-  },
-  "query": {
-    "@type": "korap:group", 
-    "operation" : "operation:sequence",
-    "operands": [
-      {
-        "@type": "korap:group", 
-        "operation": "operation:or",
-        "operands": [
-          {
-            "@type": "korap:token", 
-            "wrap": {
-              "@type": "korap:term", 
-	      "foundry": "mate", 
-              "layer": "lemma", 
-              "key" : "foo"
-            }
-          }, 
-          {
-            "@type": "korap:token", 
-            "wrap": {
-              "@type": "korap:term", 
-	      "foundry": "mate", 
-              "layer": "lemma",
-              "key" : "bar"
-            }
-          }
-        ]
-      }, 
-      {
-        "@type": "korap:token", 
-        "wrap": {
-          "@type": "korap:term", 
-	  "foundry": "mate", 
-          "layer": "lemma",
-          "key" : "foobar"
-        }
-      }
-    ]
-  }
 }
diff --git a/src/test/resources/queries/cosmas10.json b/src/test/resources/queries/cosmas10.json
index d958810..08361d2 100644
--- a/src/test/resources/queries/cosmas10.json
+++ b/src/test/resources/queries/cosmas10.json
@@ -1,5 +1,5 @@
 {
-  "context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+  "@context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
   "query" : {
     "@type" : "korap:group",
     "operation" : "operation:sequence",
@@ -38,4 +38,4 @@
       }
     } ]
   }
-}
\ No newline at end of file
+}
diff --git a/src/test/resources/queries/cosmas10b.json b/src/test/resources/queries/cosmas10b.json
index 6f84a2b..618a25f 100644
--- a/src/test/resources/queries/cosmas10b.json
+++ b/src/test/resources/queries/cosmas10b.json
@@ -1,5 +1,5 @@
 {
-  "context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+  "@context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
   "query" : {
     "@type" : "korap:group",
     "operation" : "operation:sequence",
diff --git a/src/test/resources/queries/cosmas16.json b/src/test/resources/queries/cosmas16.json
index 61333fd..b392098 100644
--- a/src/test/resources/queries/cosmas16.json
+++ b/src/test/resources/queries/cosmas16.json
@@ -1,5 +1,5 @@
 {
-  "context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+  "@context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
   "query" : {
     "@type" : "korap:group",
     "operation" : "operation:submatch",
@@ -28,4 +28,4 @@
       } ]
     } ]
   }
-}
\ No newline at end of file
+}
diff --git a/src/test/resources/queries/cosmas17.json b/src/test/resources/queries/cosmas17.json
index 32e073b..1eec888 100644
--- a/src/test/resources/queries/cosmas17.json
+++ b/src/test/resources/queries/cosmas17.json
@@ -1,5 +1,5 @@
 {
-  "context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+  "@context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
   "query" : {
     "@type" : "korap:group",
     "operation" : "operation:position",
@@ -18,4 +18,4 @@
       }
     } ]
   }
-}
\ No newline at end of file
+}
diff --git a/src/test/resources/queries/cosmas20.json b/src/test/resources/queries/cosmas20.json
index 32887c7..3a4e040 100644
--- a/src/test/resources/queries/cosmas20.json
+++ b/src/test/resources/queries/cosmas20.json
@@ -27,4 +27,4 @@
       } ]
     } ]
   }
-}
\ No newline at end of file
+}
diff --git a/src/test/resources/queries/cosmas3.json b/src/test/resources/queries/cosmas3.json
index 2c77f42..d86045e 100644
--- a/src/test/resources/queries/cosmas3.json
+++ b/src/test/resources/queries/cosmas3.json
@@ -1,5 +1,5 @@
 {
-  "context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+  "@context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
   "query" : {
     "@type" : "korap:group",
     "operation" : "operation:sequence",
@@ -28,4 +28,4 @@
       }
     } ]
   }
-}
\ No newline at end of file
+}
diff --git a/src/test/resources/queries/cosmas4.json b/src/test/resources/queries/cosmas4.json
index 2040995..2dff321 100644
--- a/src/test/resources/queries/cosmas4.json
+++ b/src/test/resources/queries/cosmas4.json
@@ -1,5 +1,5 @@
 {
-  "context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+  "@context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
   "query" : {
     "@type" : "korap:group",
     "operation" : "operation:sequence",
@@ -37,4 +37,4 @@
       }
     } ]
   }
-}
\ No newline at end of file
+}
diff --git a/src/test/resources/queries/cosmas4b.json b/src/test/resources/queries/cosmas4b.json
index 8fe2344..4b44753 100644
--- a/src/test/resources/queries/cosmas4b.json
+++ b/src/test/resources/queries/cosmas4b.json
@@ -1,5 +1,5 @@
 {
-  "context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+  "@context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
   "query" : {
     "@type" : "korap:group",
     "operation" : "operation:sequence",
diff --git a/src/test/resources/queries/cosmas5.json b/src/test/resources/queries/cosmas5.json
new file mode 100644
index 0000000..a96845d
--- /dev/null
+++ b/src/test/resources/queries/cosmas5.json
@@ -0,0 +1,55 @@
+{
+  "@context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+  "query" : {
+    "@type" : "korap:group",
+    "operation" : "operation:sequence",
+    "inOrder" : true,
+    "distances" : [ {
+      "@type" : "korap:distance",
+      "key" : "w",
+      "min" : 0,
+      "max" : 5
+    } ],
+    "operands" : [ {
+      "@type" : "korap:group",
+      "operation" : "operation:sequence",
+      "inOrder" : true,
+      "distances" : [ {
+        "@type" : "korap:distance",
+        "key" : "w",
+        "min" : 1,
+        "max" : 3
+      }, {
+        "@type" : "korap:distance",
+        "key" : "s",
+        "min" : 0,
+        "max" : 1
+      } ],
+      "operands" : [ {
+        "@type" : "korap:token",
+        "wrap" : {
+          "@type" : "korap:term",
+          "key" : "das",
+          "layer" : "orth",
+          "match" : "match:eq"
+        }
+      }, {
+        "@type" : "korap:token",
+        "wrap" : {
+          "@type" : "korap:term",
+          "key" : "Buch",
+          "layer" : "orth",
+          "match" : "match:eq"
+        }
+      } ]
+    }, {
+      "@type" : "korap:token",
+      "wrap" : {
+        "@type" : "korap:term",
+        "key" : "Tisch",
+        "layer" : "orth",
+        "match" : "match:eq"
+      }
+    } ]
+  }
+}
\ No newline at end of file
diff --git a/src/test/resources/queries/cosmas6.json b/src/test/resources/queries/cosmas6.json
new file mode 100644
index 0000000..06a9726
--- /dev/null
+++ b/src/test/resources/queries/cosmas6.json
@@ -0,0 +1,55 @@
+{
+  "@context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+  "query" : {
+    "@type" : "korap:group",
+    "operation" : "operation:sequence",
+    "inOrder" : true,
+    "distances" : [ {
+      "@type" : "korap:distance",
+      "key" : "w",
+      "min" : 0,
+      "max" : 5
+    } ],
+    "operands" : [ {
+      "@type" : "korap:token",
+      "wrap" : {
+        "@type" : "korap:term",
+        "key" : "Tisch",
+        "layer" : "orth",
+        "match" : "match:eq"
+      }
+    }, {
+      "@type" : "korap:group",
+      "operation" : "operation:sequence",
+      "inOrder" : true,
+      "distances" : [ {
+        "@type" : "korap:distance",
+        "key" : "w",
+        "min" : 1,
+        "max" : 3
+      }, {
+        "@type" : "korap:distance",
+        "key" : "s",
+        "min" : 0,
+        "max" : 1
+      } ],
+      "operands" : [ {
+        "@type" : "korap:token",
+        "wrap" : {
+          "@type" : "korap:term",
+          "key" : "das",
+          "layer" : "orth",
+          "match" : "match:eq"
+        }
+      }, {
+        "@type" : "korap:token",
+        "wrap" : {
+          "@type" : "korap:term",
+          "key" : "Buch",
+          "layer" : "orth",
+          "match" : "match:eq"
+        }
+      } ]
+    } ]
+  }
+}
\ No newline at end of file