More tutorial examples
diff --git a/Makefile.PL b/Makefile.PL
index 52d2980..f0c800b 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -22,7 +22,7 @@
     'Mojolicious::Plugin::CHI' => 0.09,
     'Cache::FastMmap' => 0,
     'Mojolicious::Plugin::Number::Commify' => '0.022',
-    'JSON::XS' => 0.0,
+#    'JSON::XS' => 0.0,
     'Mojolicious::Plugin::AssetPack' => 0.23,
     'JavaScript::Minifier::XS' => 0.09,
     'CSS::Minifier::XS' => 0.09,
diff --git a/lib/Korap.pm b/lib/Korap.pm
index 311ed48..584d31d 100644
--- a/lib/Korap.pm
+++ b/lib/Korap.pm
@@ -1,5 +1,6 @@
 package Korap;
 use Mojo::Base 'Mojolicious';
+use Mojo::ByteStream 'b';
 
 our $VERSION = '0.07';
 
diff --git a/lib/Korap/Plugin/KorapSearch.pm b/lib/Korap/Plugin/KorapSearch.pm
index a65f1f9..115bcb2 100644
--- a/lib/Korap/Plugin/KorapSearch.pm
+++ b/lib/Korap/Plugin/KorapSearch.pm
@@ -163,9 +163,9 @@
 	for ($c->stash) {
 	  $_->{'search.benchmark'}    = $benchmark;
 	  $_->{'search.itemsPerPage'} = $json->{itemsPerPage};
-	  $_->{'search.timeExceeded'} = (defined $json->{timeExceeded} &&
-	                                $json->{timeExceeded} eq true())
-	                                ? 1 : 0;
+	  $_->{'search.timeExceeded'} = ($json->{timeExceeded} &&
+					 $json->{timeExceeded}
+					   eq Mojo::JSON::true) ? 1 : 0;
 	  $_->{'search.query'}        = $json->{request}->{query};
 	  $_->{'search.hits'}         = map_matches($json->{matches});
 	};
diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep
index 71c56b3..f99e410 100644
--- a/templates/layouts/default.html.ep
+++ b/templates/layouts/default.html.ep
@@ -50,7 +50,7 @@
 <div id="top">
   <a href="<%= url_for 'index' %>"><h1><span>KorAP- Korpusanalyseplattform der nächsten Generation</span></h1></a>
 
-%= form_for $search_route, autocomplete => 'off' => begin
+%= form_for $search_route, autocomplete => 'off', begin
   <div id="searchbar">
 %= search_field 'q', id => 'q-field', autofocus => 'autofocus', placeholder => 'Find ...'
     <button type="submit"><i class="fa fa-search"></i></button>
@@ -61,8 +61,9 @@
   <% if ($location) { %><%== $location %><% } %>
   with
   <div class="select">
-    %= select_field ql => [[Poliqarp => 'poliqarp'], ['Cosmas II' => 'cosmas2'], ['Annis' => 'annis'], ['CQL v1.2' => 'cql']], id => 'ql-field'
+    %= select_field ql => [[Poliqarp => 'poliqarp'], ['Cosmas II' => 'cosmas2'], ['CQL v1.2' => 'cql']], id => 'ql-field'
   </div>
+%# ['Annis' => 'annis']
 
 <div id="button-right">
 % unless (param('q')) { param(cutoff => 1) };
diff --git a/templates/tutorial/index.html.ep b/templates/tutorial/index.html.ep
index a76de5c..686fcff 100644
--- a/templates/tutorial/index.html.ep
+++ b/templates/tutorial/index.html.ep
@@ -34,22 +34,30 @@
 <section id="tut-examples">
 
 <h3>Example Queries</h3>
-%# <p>This is a Tutorial to KorAP. It may be maintained separately (as a Wiki?) and has some nice features - like embedded example queries - just click on the queries below:</p>
+%# <p>This is a Tutorial to KorAP. For examples click on the queries below:</p>
 
 <p><strong>Poliqarp</strong>: Find all occurrences of the lemma &quot;baum&quot; as annotated by the <%= korap_tut_link_to 'default foundry', '/tutorial/foundries' %>.</p>
 %= korap_tut_query poliqarp => '[base=baum]'
 
+<p><strong>Poliqarp</strong>: Find all sequences of adjectives as annotated by Treetagger, that are repeated 3 to 5 times in a row.</p>
+%= korap_tut_query poliqarp => '[tt/p=ADJA]{3,5}'
+
 <p><strong>Cosmas-II</strong>: Find all occurrences of the words &quot;der&quot; and &quot;Baum&quot;, in case they are in a maximum distance of 5 tokens. The order is not relevant.</p>
 %= korap_tut_query cosmas2 => 'der /w5 Baum'
 
-<p><strong>Poliqarp+</strong>: Find all nominal phrases as annotated using Connexor, that contain an adverb as annotated by OpenNLP.</p>
-%= korap_tut_query poliqarp => 'contains(<cnx/c=np>,[opennlp/p=ADV])', cutoff => 1
+<p><strong>Poliqarp+</strong>: Find all nominal phrases as annotated using Connexor, that contain an adverb as annotated by OpenNLP, that is annotated as something starting with an &quot;A&quot; in Treetagger.</p>
+%= korap_tut_query poliqarp => 'contains(<cnx/c=np>,{[opennlp/p=ADV & tt/p="A.*"]})', cutoff => 1
 
-<p><strong>Poliqarp+</strong>: Find all sentences as annotated by the base foundry that start with a sequence of one token in present tense as annotated by Connexor and the lemma &quot;der&quot; annotated by the <%= korap_tut_link_to 'default foundry', '/tutorial/foundries' %>. Highlight both terms of the sequence.</p>
-%= korap_tut_query poliqarp => 'startswith(<s>, {1:[cnx/m=PRES]}{2:[base=der]})', cutoff => 1
+<p><strong>Poliqarp+</strong>: Find all sentences as annotated by the base foundry that start with a sequence of one token in present tense as annotated by Connexor and the lemma &quot;die&quot; annotated by the <%= korap_tut_link_to 'default foundry', '/tutorial/foundries' %>. Highlight both terms of the sequence.</p>
+%= korap_tut_query poliqarp => 'startswith(<s>, {1:[cnx/m=PRES]}{2:[base=die]})', cutoff => 1
 
-<p><strong>Annis</strong>: Find all occurrences of the sequence of two tokens annotated as adverbs by the <%= korap_tut_link_to 'default foundry', '/tutorial/foundries' %>.</p>
-%= korap_tut_query annis => 'pos="ADV" & pos="ADV" & #1 . #2'
+
+%# <p><strong>Annis</strong>: Find all occurrences of the sequence of two tokens annotated as adverbs by the <%= korap_tut_link_to 'default foundry', '/tutorial/foundries' %>.</p>
+%# %= korap_tut_query annis => 'pos="ADV" & pos="ADV" & #1 . #2'
+
+
+<p><strong>CQL</strong>: Find all occurrences of the sequence &quot;der alte Mann&quot;.
+%= korap_tut_query cql => '"der alte Mann"'
 
 
 </section>
diff --git a/templates/tutorial/poliqarp-plus.html.ep b/templates/tutorial/poliqarp-plus.html.ep
index f9a778d..e7017d4 100644
--- a/templates/tutorial/poliqarp-plus.html.ep
+++ b/templates/tutorial/poliqarp-plus.html.ep
@@ -101,7 +101,7 @@
     However, they work in case they are part of a <a href="#tut-syntagmatic-operators-sequence">sequence</a>.</p>
 </blockquote>
 
-<h4>Empty Segments</h4>
+<h4 id="empty-segments">Empty Segments</h4>
 
 <p>A special segment is the empty segment, that matches every word in the index.</p>
 
@@ -125,6 +125,7 @@
 %= korap_tut_query poliqarp => '<xip/c=INFC>'
 
 <p>Otherwise they can be treated in exactly the same way as simple or complex segments.</p>
+
 </section>
 
 
@@ -174,6 +175,9 @@
 
 %= korap_tut_query poliqarp => '[orth=der][][orth=Mann]'
 
+<p>You are also able to mix segments and spans in sequences, for example to search for the word &quot;Der&quot; at the beginning of a sentence (which can be interpreted as the first word after the end of a sentence).</p>
+
+%= korap_tut_query poliqarp => '<s>[orth=Der]'
 
 <h4>Groups</h4>
 
@@ -215,51 +219,75 @@
 
 <p>To search for a sequence of the lemma <code>der</code> followed by the lemma <code>baum</code> as annotated by the base foundry, but allowing an optional adjective as annotated by the TreeTagger foundry in between, you can search for:</p>
 
-%= korap_tut_query poliqarp => '[base=der][tt/pos=ADJA]?[base=Baum]'
+%= korap_tut_query poliqarp => '[base=die][tt/pos=ADJA]?[base=Baum]'
 
 <p>This query is identical to the numbered quantification of:</p>
 
-%= korap_tut_query poliqarp => '[base=der][tt/pos=ADJA]{,1}[base=Baum]'
+%= korap_tut_query poliqarp => '[base=die][tt/pos=ADJA]{,1}[base=Baum]'
 
 <p>To search for the same sequences but with unlimited adjectives as annotated by the TreeTagger foundry in between, you can use the Kleene Star:</p>
 
-%= korap_tut_query poliqarp => '[base=der][tt/pos=ADJA]*[base=Baum]'
+%= korap_tut_query poliqarp => '[base=die][tt/pos=ADJA]*[base=Baum]'
 
 <p>And to search for this sequence but with at least one adjective in between, you can use the Kleene Plus (all queries are identical):</p>
 
-%= korap_tut_query poliqarp => '[base=der][tt/pos=ADJA]+[base=Baum]'
-%= korap_tut_query poliqarp => '[base=der][tt/pos=ADJA]{1,}[base=Baum]'
-%= korap_tut_query poliqarp => '[base=der][tt/pos=ADJA][tt/pos=ADJA]*[base=Baum]'
+%= korap_tut_query poliqarp => '[base=die][tt/pos=ADJA]+[base=Baum]', cutoff => 1
+%= korap_tut_query poliqarp => '[base=die][tt/pos=ADJA]{1,}[base=Baum]', cutoff => 1
+%= korap_tut_query poliqarp => '[base=die][tt/pos=ADJA][tt/pos=ADJA]*[base=Baum]', cutoff => 1
 
 <blockquote class="warning">
-  <p>Repetition operators like <code>{,4}</code>, <code>?</code>, and <code>*</code> make segments or groups of segments optional. In case these queries are used separated (and there are no mandatory segments in the query), you will be warned by the system that your query won't be treated as optional. Keep in mind that optionality may be somehow <i>inherited</i>, for example when you search for <code>(junge|alte)?|tote</code>, one segment of the alternation is optional, which makes the whole query optional as well.</p>
+  <p>Repetition operators like <code>{,4}</code>, <code>?</code>, and <code>*</code> make segments or groups of segments optional. In case these queries are used separated and not in a sequence (and there are no mandatory segments in the query), you will be warned by the system that your query won't be treated as optional.</p>
+  <p>Keep in mind that optionality may be somehow <i>inherited</i>, for example when you search for <code>(junge|alte)?|tote</code>, one segment of the alternation is optional, which makes the whole query optional as well.</p>
 </blockquote>
 
-%= korap_tut_query poliqarp => '[base=der][][base=Baum]'
-%= korap_tut_query poliqarp => '[base=der][]{2}[base=Baum]'
-%= korap_tut_query poliqarp => '[base=der][]{2,}[base=Baum]'
-%= korap_tut_query poliqarp => '[base=der][]{,3}[base=Baum]'
+<p>Repetition can also be used to express distances between segments by using <a href="#empty-segments">empty segments</a>.</p>
 
-%#= korap_tut_query poliqarp => '[base=der][tt/pos=ADJA]*[base=Baum]'
-%#= korap_tut_query poliqarp => '[base=der][tt/pos=ADJA]+[base=Baum]'
+%= korap_tut_query poliqarp => '[base=die][][base=Baum]'
+%= korap_tut_query poliqarp => '[base=die][]{2}[base=Baum]', cutoff => 1
+%= korap_tut_query poliqarp => '[base=die][]{2,}[base=Baum]', cutoff => 1
+%= korap_tut_query poliqarp => '[base=die][]{,3}[base=Baum]', cutoff => 1
+
+<p>Of course, Kleene operators can be used with empty segments as well.</p>
+
+%= korap_tut_query poliqarp => '[base=die][]?[base=Baum]'
+%= korap_tut_query poliqarp => '[base=die][]*[base=Baum]', cutoff => 1
+%= korap_tut_query poliqarp => '[base=die][]+[base=Baum]', cutoff => 1
 
 <h4>Position</h4>
 
-%#= korap_tut_query poliqarp => 'matches(<s>,[])'
-%# matches(<s>,[cnx/p=INTERJ]{2})
-<p>contains()</p>
-<p>startsWith()</p>
-<p>endsWith()</p>
+<p>Sequences as shown above can all be nested in further complex queries and treated as subqueries (see <a href="#tut-class-operators">class operators</a> on how to later access these subqueries directly).</p>
+<p>Positional operators compare two matches of subqueries and will match, in case a certain condition regarding the position of both is true.</p>
+<p>The <code>contains()</code> operation will match, when a second subquery matches inside the span of a first subquery.</p>
+
+%= korap_tut_query poliqarp => 'contains(<s>, [tt/p=KOUS])', cutoff => 1
+
+<p>The <code>startsWith()</code> operation will match, when a second subquery matches at the beginning of the span of a first subquery.</p>
+
+%= korap_tut_query poliqarp => 'startsWith(<s>, [tt/p=KOUS])', cutoff => 1
+
+<p>The <code>endsWith()</code> operation will match, when a second subquery matches at the end of the span of a first subquery.</p>
+
+%= korap_tut_query poliqarp => 'endsWith(<s>, [opennlp/p=NN])', cutoff => 1
+
+<p>The <code>matches()</code> operation will match, when a second subquery has the exact same span of a first subquery.</p>
+
+%= korap_tut_query poliqarp => 'matches(<s>,[tt/p=CARD][tt/p="N.*"])', cutoff => 1
+
+<!--
 <p>overlaps()</p>
+-->
 
 <blockquote class="warning">
-  <p>Optional operands in position operators, like in <code>within(&lt;s&gt;,[orth=Baum]*)</code>, have to be mandatory at the moment and will be reformulated to occur at least once.</p>
+  <p>Positional operators are still experimental and may change in certain aspects in the future (although the behaviour defined is intended to be stable). There is also known incorrect behaviour which will be corrected in future versions.</p>
+  <p>Optional operands in position operators, like in <code>contains(&lt;s&gt;,[orth=Baum]*)</code>, have to be mandatory at the moment and will be reformulated to occur at least once.</p>
   <p>This behaviour may change in the future.</p>
 </blockquote>
 
+<!--
 <blockquote>
   <p>The KorAP implementation of Poliqarp also supports the postfix <code>within</code> operator, that works similar to the <code>contains()</code> operator, but is not nestable.</p>
 </blockquote>
+-->
 
 </section>
 <section id="tut-class-operators">