Fixed query deserialization for sequences with multiple non-anchors
diff --git a/src/test/resources/queries/bsp-class.jsonld b/src/test/resources/queries/bsp-class.jsonld
index 075f927..b4fd65e 100644
--- a/src/test/resources/queries/bsp-class.jsonld
+++ b/src/test/resources/queries/bsp-class.jsonld
@@ -3,7 +3,7 @@
   "query":{
     "@type":"korap:group",
     "operation" : "operation:class",
-   "class":0,
+   "class":1,
     "operands":[
       {
 	"@type":"korap:group",
diff --git a/src/test/resources/queries/bugs/cosmas_classrefcheck.jsonld b/src/test/resources/queries/bugs/cosmas_classrefcheck.jsonld
new file mode 100644
index 0000000..bd0c08b
--- /dev/null
+++ b/src/test/resources/queries/bugs/cosmas_classrefcheck.jsonld
@@ -0,0 +1,65 @@
+{
+  "@context": "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+  "warnings":[
+    "This is a warning coming from the serialization"
+  ],
+  "query": {
+    "@type" : "korap:reference",
+    "classRef" : [
+      130
+    ],
+    "operands" : [
+      {
+        "@type" : "korap:group",
+        "class" : 131,
+        "classIn" : [
+          129,
+          130
+        ],
+        "classOut" : 131,
+        "classRefCheck" : "classRefCheck:includes",
+        "operands" : [
+          {
+            "@type" : "korap:group",
+            "frame" : "frame:contains",
+            "frames" : [],
+            "operands" : [
+              {
+                "@type" : "korap:group",
+                "class" : 129,
+                "classOut" : 129,
+                "operands" : [
+                  {
+                    "@type" : "korap:span",
+                    "key" : "s"
+                  }
+                ],
+                "operation" : "operation:class"
+              },
+              {
+                "@type" : "korap:group",
+                "class" : 130,
+                "classOut" : 130,
+                "operands" : [
+                  {
+                    "@type" : "korap:token",
+                    "wrap" : {
+                      "@type" : "korap:term",
+                      "key" : "wegen",
+                      "layer" : "orth",
+                      "match" : "match:eq"
+                    }
+                  }
+                ],
+                "operation" : "operation:class"
+              }
+            ],
+            "operation" : "operation:position"
+          }
+        ],
+        "operation" : "operation:class"
+      }
+    ],
+    "operation" : "operation:focus"
+  }
+}
diff --git a/src/test/resources/queries/bugs/multiterm_rewrite.jsonld b/src/test/resources/queries/bugs/multiterm_rewrite.jsonld
new file mode 100644
index 0000000..c07f88c
--- /dev/null
+++ b/src/test/resources/queries/bugs/multiterm_rewrite.jsonld
@@ -0,0 +1,64 @@
+{
+  "@context":"http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld",
+  "errors":[],
+  "warnings":[],
+  "announcements":[
+    "Deprecated 2014-07-24: 'min' and 'max' to be supported until 3 months from deprecation date."
+  ],
+  "collection":{},
+  "meta":{
+    "startPage":1,
+    "context":"paragraph"
+  },
+  "query":{
+    "@type":"korap:group",
+    "operation":"operation:sequence",
+    "operands":[
+      {
+	"@type":"korap:group",
+	"operation":"operation:repetition",
+	"operands":[
+	  {
+	    "@type":"korap:token",
+	    "wrap":{
+	      "@type":"korap:term",
+	      "foundry":"tt",
+	      "layer":"p",
+	      "type":"type:regex",
+	      "key":"A.*",
+	      "match":"match:eq"
+	    }
+	  }
+	],
+	"boundary":{
+	  "@type":"korap:boundary",
+	  "min":0,
+	  "max":3
+	},
+	"min":0,
+	"max":3
+      },
+      {
+	"@type":"korap:token",
+	"wrap":{
+	  "@type":"korap:term",
+	  "foundry":"tt",
+	  "layer":"p",
+	  "type":"type:regex",
+	  "key":"N.*",
+	  "match":"match:eq"
+	}
+      }
+    ]
+  },
+  "collections":[
+    {
+      "@type":"korap:meta-filter",
+      "@value":{
+	"@type":"korap:term",
+	"@field":"korap:field#corpusID",
+	"@value":"WPD"
+      }
+    }
+  ]
+}
diff --git a/src/test/resources/queries/sequence/multiple-distances.jsonld b/src/test/resources/queries/sequence/multiple-distances.jsonld
new file mode 100644
index 0000000..4187ded
--- /dev/null
+++ b/src/test/resources/queries/sequence/multiple-distances.jsonld
@@ -0,0 +1,70 @@
+{
+  "@context": "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+  "query": {
+    "@type" : "korap:group",
+    "distances" : [
+      {
+        "@type" : "korap:distance",
+        "boundary" : {
+          "@type" : "korap:boundary",
+          "max" : 11,
+          "min" : 1
+        },
+        "key" : "w",
+        "max" : 11,
+        "min" : 1
+      }
+    ],
+    "inOrder" : true,
+    "operands" : [
+      {
+        "@type" : "korap:token",
+        "wrap" : {
+          "@type" : "korap:term",
+          "key" : "er",
+          "layer" : "orth",
+          "match" : "match:eq"
+        }
+      },
+      {
+        "@type" : "korap:group",
+        "distances" : [
+          {
+            "@type" : "korap:distance",
+            "boundary" : {
+              "@type" : "korap:boundary",
+              "max" : 11,
+              "min" : 2
+            },
+            "key" : "w",
+            "max" : 11,
+            "min" : 2
+          }
+        ],
+        "inOrder" : true,
+        "operands" : [
+          {
+            "@type" : "korap:token",
+            "wrap" : {
+              "@type" : "korap:term",
+              "key" : "kann",
+              "layer" : "orth",
+              "match" : "match:eq"
+            }
+          },
+          {
+            "@type" : "korap:token",
+            "wrap" : {
+              "@type" : "korap:term",
+              "key" : "sagte",
+              "layer" : "orth",
+              "match" : "match:eq"
+            }
+          }
+        ],
+        "operation" : "operation:sequence"
+      }
+    ],
+    "operation" : "operation:sequence"
+  }
+}