filled test class, support earlier bugs when using spaces, need to look at occurrence
diff --git a/pom.xml b/pom.xml
index 33c05c5..e3749d5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -52,6 +52,11 @@
           <artifactId>joda-time</artifactId>
           <version>2.2</version>
       </dependency>
+      <dependency>
+      	<groupId>commons-lang</groupId>
+      	<artifactId>commons-lang</artifactId>
+      	<version>2.6</version>
+      </dependency>
   </dependencies>
   <build>
     <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
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 d797c0a..827e5e3 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
@@ -578,7 +578,10 @@
 				topSequenceOperands.add(positionGroup); 
 			} else if (openNodeCats.get(2).equals("query")) {
 				requestMap.put("query", positionGroup);	
-			} 
+			} else {
+				ArrayList<Object> topSequenceOperands = (ArrayList<Object>) objectStack.get(1).get("operands");
+				topSequenceOperands.add(positionGroup); 
+			}
 		}
 		
 		if (nodeCat.equals("shrink")) {
@@ -716,7 +719,7 @@
 		return false;
 	}
 	
-	private static void checkUnbalancedPars(String q) {
+	private static void checkUnbalancedPars(String q) throws IllegalArgumentException {
 		int openingPars = StringUtils.countMatches(q, "(");
 		int closingPars = StringUtils.countMatches(q, ")");
 		int openingBrkts = StringUtils.countMatches(q, "[");
@@ -733,7 +736,7 @@
 		
 	}
 	
-	private static ParserRuleContext parsePoliqarpQuery (String p) {
+	private static ParserRuleContext parsePoliqarpQuery (String p) throws IllegalArgumentException {
 		checkUnbalancedPars(p);
 		
 		Lexer poliqarpLexer = new PoliqarpPlusLexer((CharStream)null);
@@ -774,23 +777,13 @@
 		 * For testing
 		 */
 		String[] queries = new String[] {
-				"[base=foo]|([base=foo][base=bar])* meta author=Goethe&year=1815",
-				"within(<np>,[base=foo])",
-				"[mate/p=ADJA]",
-				"[mate_p=ADJA]{[mate_p=NN]}",
-				"within(<s>,[mate_p=ADJA][mate_p=NN])",
-				"within(<s>,{2:{1:[tt_p=ADJA]}[mate_p=NN]})",
-				"within(<p>, within(<s>, [mate_p=NN]))",
-				"within(<p>,within(<s>,<np>))",
-				"shrink(3:startswith(<s>,{3:[base=der]{1:[mate_p=ADJA]{2:[tt_p=NN]}}})) ",
-				"shrink(startswith(<s>,<s>))",
-				"shrink(3:startswith(<s>,<s>))",
-				"shrink(1:[base=foo]{[base=bar]})",
-				"[base=Auto]contains(<s>,[base=Mann])",
-				"shrink([orth=Der]{[orth=Mann]})",
-				"shrink([orth=Der]{[orth=Mann][orth=geht]})"
+				"shrink(startswith(<s>,{<np>}))",
+				"shrink(1: startswith(<s>,{1:<np>}))",
+				"contains(<p>, startswith(<s>,<np>))",
+				"[base=bar][base=foo]*"
+				
 		};
-//		PoliqarpPlusTree.verbose=true;
+		PoliqarpPlusTree.verbose=true;
 		for (String q : queries) {
 			try {
 				System.out.println(q);
diff --git a/src/test/java/PoliqarpPlusTreeTest.java b/src/test/java/PoliqarpPlusTreeTest.java
index 63437f2..de9e493 100644
--- a/src/test/java/PoliqarpPlusTreeTest.java
+++ b/src/test/java/PoliqarpPlusTreeTest.java
@@ -79,6 +79,37 @@
 	
 	@Test
 	public void testOccurrence() {
+		// [base=foo]*
+		String occ1 = "{@type=korap:group, operands=[" +
+					     "{@type=korap:token, @value={@type=korap:term, @value=base:foo, relation==}}" +
+					  "], relation=repetition, quantifier=* }"; 
+		ppt = new PoliqarpPlusTree("[base=foo]*");
+		map = ppt.getRequestMap().get("query").toString();
+		assertEquals(occ1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+		
+		// [base=foo]*[base=bar]
+		String occ2 = 
+				"{@type=korap:sequence, operands=[" +
+					"{@type=korap:group, operands=[" +
+					     "{@type=korap:token, @value={@type=korap:term, @value=base:foo, relation==}}" +
+					"], relation=repetition, quantifier=* }," +
+					"{@type=korap:token, @value={@type=korap:term, @value=base:bar, relation==}}" +
+				"]}"; 
+		ppt = new PoliqarpPlusTree("[base=foo]*[base=bar]");
+		map = ppt.getRequestMap().get("query").toString();
+		assertEquals(occ2.replaceAll(" ", ""), map.replaceAll(" ", ""));
+		
+		// [base=bar][base=foo]*
+		String occ3 = 
+				"{@type=korap:sequence, operands=[" +
+					"{@type=korap:token, @value={@type=korap:term, @value=base:bar, relation==}}," +
+					"{@type=korap:group, operands=[" +
+					     "{@type=korap:token, @value={@type=korap:term, @value=base:foo, relation==}}" +
+					"], relation=repetition, quantifier=* }" +
+				"]}"; 
+		ppt = new PoliqarpPlusTree("[base=bar][base=foo]*");
+		map = ppt.getRequestMap().get("query").toString();
+		assertEquals(occ3.replaceAll(" ", ""), map.replaceAll(" ", ""));
 	}
 	
 	@Test
@@ -182,6 +213,19 @@
 						"{@type=korap:token, @value={@type=korap:term, @value=p:NN, relation==}}" +
 					  "]}";
 		assertTrue(equalsQueryContent(cls4, "{[base=Mann][orth=Frau]}[p=NN]"));
+
+		// {2:{1:[tt/p=ADJA]}[mate/p=NN]}"
+		String cls5 = "{@type=korap:group, class=2, operands=[" +
+						"{@type=korap:sequence, operands=[" +
+						   "{@type=korap:group, class=1, operands=[" +
+						     "{@type=korap:token, @value={@type=korap:term, @value=tt/p:ADJA, relation==}}" +
+						   "]}," +
+						   "{@type=korap:token, @value={@type=korap:term, @value=mate/p:NN, relation==}}" + 
+						"]}" +
+					  "]}";
+		ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}");
+		map = ppt.getRequestMap().get("query").toString();
+		assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", ""));
 	}
 	
 	@Test
@@ -237,7 +281,7 @@
 					"{@type=korap:token, @value={@type=korap:term, @value=orth:Der, relation==}}" +
 				"]}" +
 			"]}";
-		ppt = new PoliqarpPlusTree("contains(<s>,startswith(<np>,[orth=Der]))");
+		ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))");
 		map = ppt.getRequestMap().get("query").toString();
 		assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
 	}
@@ -302,13 +346,40 @@
 					"]}" +
 				"]}" +
 			"]}";
-		ppt = new PoliqarpPlusTree("shrink(1:startswith(<s>,{1:<np>}))");
+		ppt = new PoliqarpPlusTree("shrink(1: startswith(<s>,{1:<np>}))");
 		map = ppt.getRequestMap().get("query").toString();
 		assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", ""));
+		
+		// shrink(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) 
+		String shr5 = 
+			"{@type=korap:group, relation=shrink, shrink=3, operands=[" +
+				"{@type=korap:group, relation=position, position=startswith, operands=[" +
+					"{@type=korap:element, @value=s}," +
+					"{@type=korap:group, class=3, operands=[" +
+						"{@type=korap:sequence, operands=[" +
+							"{@type=korap:token, @value={@type=korap:term, @value=base:der, relation==}}," +
+							"{@type=korap:group, class=1, operands=[" +
+								"{@type=korap:sequence, operands=[" +
+									"{@type=korap:token, @value={@type=korap:term, @value=mate/p:ADJA, relation==}}," +
+									"{@type=korap:group, class=2, operands=[" +
+										"{@type=korap:token, @value={@type=korap:term, @value=tt/p:NN, relation==}}" +
+									"]}" + 
+								"]}" +
+							"]}" +
+						"]}" +
+					"]}" +
+				"]}" +
+			"]}";
+		ppt = new PoliqarpPlusTree("shrink(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
+		map = ppt.getRequestMap().get("query").toString();
+		assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", ""));
 	}
 	
 	@Test
 	public void testLayers() {
+		// [base=Mann]
+		String layer1 = "{@type=korap:token, @value={@type=korap:term, @value=tt/base:Mann, relation==}}";
+		assertTrue(equalsQueryContent(layer1, "[tt/base=Mann]"));
 		
 	}
 }