bugfix for multithreaded environments
diff --git a/src/test/java/de/ids_mannheim/korap/filter/TestKorapCollectionJSON.java b/src/test/java/de/ids_mannheim/korap/filter/TestKorapCollectionJSON.java
index 4296da4..2d10b6f 100644
--- a/src/test/java/de/ids_mannheim/korap/filter/TestKorapCollectionJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/filter/TestKorapCollectionJSON.java
@@ -50,7 +50,8 @@
 		contentBuilder.append(str);
 	    };
 	    in.close();
-	} catch (IOException e) {
+	}
+	catch (IOException e) {
 	    fail(e.getMessage());
 	}
 	return contentBuilder.toString();
diff --git a/src/test/resources/queries/cosmas10.json b/src/test/resources/queries/cosmas10.json
new file mode 100644
index 0000000..d958810
--- /dev/null
+++ b/src/test/resources/queries/cosmas10.json
@@ -0,0 +1,41 @@
+{
+  "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",
+        "key" : "Institut",
+        "layer" : "orth",
+        "match" : "match:eq"
+      }
+    }, {
+      "@type" : "korap:token",
+      "wrap" : {
+        "@type" : "korap:term",
+        "key" : "für",
+        "layer" : "orth",
+        "match" : "match:eq"
+      }
+    }, {
+      "@type" : "korap:token",
+      "wrap" : {
+        "@type" : "korap:term",
+        "caseInsensitive" : true,
+        "key" : "deutsche",
+        "layer" : "orth",
+        "match" : "match:eq"
+      }
+    }, {
+      "@type" : "korap:token",
+      "wrap" : {
+        "@type" : "korap:term",
+        "key" : "Sprache",
+        "layer" : "orth",
+        "match" : "match:eq"
+      }
+    } ]
+  }
+}
\ No newline at end of file
diff --git a/src/test/resources/queries/cosmas16.json b/src/test/resources/queries/cosmas16.json
new file mode 100644
index 0000000..61333fd
--- /dev/null
+++ b/src/test/resources/queries/cosmas16.json
@@ -0,0 +1,31 @@
+{
+  "context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+  "query" : {
+    "@type" : "korap:group",
+    "operation" : "operation:submatch",
+    "classRef" : [ 1 ],
+    "operands" : [ {
+      "@type" : "korap:group",
+      "operation" : "operation:position",
+      "frame" : "frame:startswith",
+      "operands" : [ {
+        "@type" : "korap:span",
+        "key" : "s"
+      }, {
+        "@type" : "korap:group",
+        "operation" : "operation:class",
+        "class" : 1,
+        "operands" : [ {
+          "@type" : "korap:token",
+          "wrap" : {
+            "@type" : "korap:term",
+            "caseInsensitive" : true,
+            "key" : "wegen",
+            "layer" : "orth",
+            "match" : "match:eq"
+          }
+        } ]
+      } ]
+    } ]
+  }
+}
\ No newline at end of file
diff --git a/src/test/resources/queries/cosmas17.json b/src/test/resources/queries/cosmas17.json
new file mode 100644
index 0000000..32e073b
--- /dev/null
+++ b/src/test/resources/queries/cosmas17.json
@@ -0,0 +1,21 @@
+{
+  "context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+  "query" : {
+    "@type" : "korap:group",
+    "operation" : "operation:position",
+    "frame" : "frame:startswith",
+    "operands" : [ {
+      "@type" : "korap:span",
+      "key" : "s"
+    }, {
+      "@type" : "korap:token",
+      "wrap" : {
+        "@type" : "korap:term",
+        "caseInsensitive" : true,
+        "key" : "wegen",
+        "layer" : "orth",
+        "match" : "match:eq"
+      }
+    } ]
+  }
+}
\ No newline at end of file
diff --git a/src/test/resources/queries/cosmas20.json b/src/test/resources/queries/cosmas20.json
new file mode 100644
index 0000000..32887c7
--- /dev/null
+++ b/src/test/resources/queries/cosmas20.json
@@ -0,0 +1,30 @@
+{
+  "context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+  "query" : {
+    "@type" : "korap:group",
+    "operation" : "operation:submatch",
+    "classRef" : [ 1 ],
+    "operands" : [ {
+      "@type" : "korap:group",
+      "operation" : "operation:position",
+      "frame" : "frame:endswith",
+      "operands" : [ {
+        "@type" : "korap:span",
+        "key" : "s"
+      }, {
+        "@type" : "korap:group",
+        "operation" : "operation:class",
+        "class" : 1,
+        "operands" : [ {
+          "@type" : "korap:token",
+          "wrap" : {
+            "@type" : "korap:term",
+            "key" : "V",
+            "layer" : "pos",
+            "match" : "match:eq"
+          }
+        } ]
+      } ]
+    } ]
+  }
+}
\ No newline at end of file
diff --git a/src/test/resources/queries/cosmas3.json b/src/test/resources/queries/cosmas3.json
new file mode 100644
index 0000000..2c77f42
--- /dev/null
+++ b/src/test/resources/queries/cosmas3.json
@@ -0,0 +1,31 @@
+{
+  "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" : 1,
+      "max" : 3
+    } ],
+    "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
diff --git a/src/test/resources/queries/cosmas4.json b/src/test/resources/queries/cosmas4.json
new file mode 100644
index 0000000..2040995
--- /dev/null
+++ b/src/test/resources/queries/cosmas4.json
@@ -0,0 +1,40 @@
+{
+  "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:group",
+      "operation" : "operation:and",
+      "operands" : [ {
+        "@type" : "korap:distance",
+        "key" : "w",
+        "min" : 1,
+        "max" : 3
+      }, {
+        "@type" : "korap:distance",
+        "key" : "s",
+        "min" : 1,
+        "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
diff --git a/src/test/resources/queries/readme.txt b/src/test/resources/queries/readme.txt
index f6f2584..2aa2f2e 100644
--- a/src/test/resources/queries/readme.txt
+++ b/src/test/resources/queries/readme.txt
@@ -1,19 +1,27 @@
-bsp1.json:   [base=foo]|([base=foo][base=bar])* meta author=Goethe&year=1815
-bsp1b.json:  [base=foo]|([base=foo][base=bar]) meta author=Goethe&year=1815
-bsp2.json:   ([base=foo]|[base=bar])[base=foobar]
-bsp3.json:   shrink({[base=Mann]})
-bsp4.json:   shrink({[base=foo]}[orth=bar])
-bsp5.json:   shrink(1:[base=Der]{1:[base=Mann]}) 
-bsp6.json:   [base=Katze]
-bsp7.json:   [base!=Katze]
-bsp8.json:   [!base=Katze]
-bsp9.json:   [base=Katze&orth=Katzen]
-bsp10.json:  [base=Katze][orth=und][orth=Hunde]
-bsp11.json:  [!(base=Katze&orth=Katzen)]
-bsp12.json:  contains(<np>,[base=Mann])
-bsp13.json:  startswith(<np>,[!pos=Det])
-bsp13b.json: startswith(<np>,[pos=Det])
-bsp14.json:  'vers{2,3}uch'
-bsp15.json:  [orth='vers.*ch']
-bsp16.json:  [(base=bar|base=foo)&orth=foobar]
-bsp17.json:  within(<np>,[base=Mann])
+bsp1:   [base=foo]|([base=foo][base=bar])* meta author=Goethe&year=1815
+bsp1b:  [base=foo]|([base=foo][base=bar]) meta author=Goethe&year=1815
+bsp2:   ([base=foo]|[base=bar])[base=foobar]
+bsp3:   shrink({[base=Mann]})
+bsp4:   shrink({[base=foo]}[orth=bar])
+bsp5:   shrink(1:[base=Der]{1:[base=Mann]}) 
+bsp6:   [base=Katze]
+bsp7:   [base!=Katze]
+bsp8:   [!base=Katze]
+bsp9:   [base=Katze&orth=Katzen]
+bsp10:  [base=Katze][orth=und][orth=Hunde]
+bsp11:  [!(base=Katze&orth=Katzen)]
+bsp12:  contains(<np>,[base=Mann])
+bsp13:  startswith(<np>,[!pos=Det])
+bsp13b: startswith(<np>,[pos=Det])
+bsp14:  'vers{2,3}uch'
+bsp15:  [orth='vers.*ch']
+bsp16:  [(base=bar|base=foo)&orth=foobar]
+bsp17:  within(<np>,[base=Mann])
+
+// Based on KorAP-querySerialization/examples/
+cosmas3:  "das /+w1:3 Buch" # word-distance constraint
+cosmas4:  "das /+w1:3,s1 Buch" # combined word-distance and sent-distance constraint
+cosmas10: "Institut für $deutsche Sprache" # finds both
+cosmas16: "$wegen #IN(L) <s>"  # finds 'wegen' at beginning of sentence, also when capitalised
+cosmas17: "#BED($wegen , +sa)" # equivalent to above
+cosmas20: "MORPH(V) #IN(R) #ELEM(S)" # e.g. subordinate clauses