Fixed NullPointer Exception in WithinSpans
diff --git a/Changes b/Changes
index 3bc1681..1b2dba8 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,4 @@
-0.49.3 2014-01-30
+0.49.3 2014-02-03
         - [documentation] Improved documentation for API classes (diewald)
 	- [documentation] Improved documentation for various queries (margaretha)
 	- [feature] Added deserialization of SpanSubSpanQueries (margaretha,diewald)
@@ -9,6 +9,8 @@
 	- [bugfix] Empty class segments are now correctly serialized
 	  in sequences (diewald)
 	- [feature] Started support for position frames (diewald)
+	- [bugfix] Fixed #134 Nullpointer exception in WithinSpans
+	  (diewald, margaretha)
 
 0.49.2 2014-12-05
 	- [documentation] Improved documentation for various queries (margaretha)
diff --git a/src/main/java/de/ids_mannheim/korap/KorapQuery.java b/src/main/java/de/ids_mannheim/korap/KorapQuery.java
index 027161f..8747413 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapQuery.java
@@ -10,20 +10,7 @@
 import com.fasterxml.jackson.databind.ObjectMapper;
 
 import de.ids_mannheim.korap.query.SpanWithinQuery;
-import de.ids_mannheim.korap.query.wrap.SpanAlterQueryWrapper;
-import de.ids_mannheim.korap.query.wrap.SpanAttributeQueryWrapper;
-import de.ids_mannheim.korap.query.wrap.SpanClassQueryWrapper;
-import de.ids_mannheim.korap.query.wrap.SpanElementQueryWrapper;
-import de.ids_mannheim.korap.query.wrap.SpanMatchModifyQueryWrapper;
-import de.ids_mannheim.korap.query.wrap.SpanQueryWrapper;
-import de.ids_mannheim.korap.query.wrap.SpanRegexQueryWrapper;
-import de.ids_mannheim.korap.query.wrap.SpanRepetitionQueryWrapper;
-import de.ids_mannheim.korap.query.wrap.SpanSegmentQueryWrapper;
-import de.ids_mannheim.korap.query.wrap.SpanSequenceQueryWrapper;
-import de.ids_mannheim.korap.query.wrap.SpanSimpleQueryWrapper;
-import de.ids_mannheim.korap.query.wrap.SpanSubspanQueryWrapper;
-import de.ids_mannheim.korap.query.wrap.SpanWildcardQueryWrapper;
-import de.ids_mannheim.korap.query.wrap.SpanWithinQueryWrapper;
+import de.ids_mannheim.korap.query.wrap.*;
 import de.ids_mannheim.korap.response.Notifications;
 import de.ids_mannheim.korap.util.QueryException;
 
@@ -954,6 +941,7 @@
     };
 
 
+    // Get attributes from a json termgroup
     private SpanQueryWrapper _attrFromJson (JsonNode attrNode)
         throws QueryException {
 
@@ -993,6 +981,13 @@
     }
 
 
+
+    /*
+     * Following are builder methods that will probably move
+     * to a separated class in the future
+     */
+
+
     /**
      * Create a query object based on a regular expression.
      *
diff --git a/src/main/java/de/ids_mannheim/korap/query/FrameConstraint.java b/src/main/java/de/ids_mannheim/korap/query/FrameConstraint.java
index d035463..77edc69 100644
--- a/src/main/java/de/ids_mannheim/korap/query/FrameConstraint.java
+++ b/src/main/java/de/ids_mannheim/korap/query/FrameConstraint.java
@@ -3,7 +3,52 @@
 import java.util.*;
 
 /**
- * Class representing a frame constraint as a bit vector.
+ * Class representing a frame constraint, as used by
+ * {@link SpanWithinQuery}.
+ * Multiple constraints are represented as a bit vector,
+ * supporting fast checks if a certain condition is met.
+ * The following distinctive frame conditions are supported:
+ *
+ * <dl>
+ *   <dt>precedes</dt>
+ *   <dd>A precedes B</dd>
+ *
+ *   <dt>precedesDirectly</dt>
+ *   <dd>A precedes B directly</dd>
+ *
+ *   <dt>overlapsLeft</dt>
+ *   <dd>A overlaps B to the left</dd>
+ *
+ *   <dt>alignsLeft</dt>
+ *   <dd>A aligns with B to the left</dd>
+ *
+ *   <dt>startsWith</dt>
+ *   <dd>A starts with B</dd>
+ *
+ *   <dt>matches</dt>
+ *   <dd>A matches B</dd>
+ *
+ *   <dt>isWithin</dt>
+ *   <dd>A is within B</dd>
+ *
+ *   <dt>isAround</dt>
+ *   <dd>A is around B</dd>
+ *
+ *   <dt>endsWith</dt>
+ *   <dd>A ends with B</dd>
+ *
+ *   <dt>alignsRight</dt>
+ *   <dd>A aligns with B to the right</dd>
+ *
+ *   <dt>overlapsRight</dt>
+ *   <dd>A overlaps B to the right</dd>
+ *
+ *   <dt>succeedsDirectly</dt>
+ *   <dd>A succeeds B directly</dd>
+ *
+ *   <dt>succeeds</dt>
+ *   <dd>A succeeds B</dd>
+ * </dl>
  *
  * @author diewald
  */
@@ -149,12 +194,23 @@
     // Bitvector representing the frame constraint
     public int vector;
 
+    /**
+     * Constructs a new Frame Constraint.
+     */
     public FrameConstraint () {
         this.vector = 0;
     };
 
-    public FrameConstraint or (String constraint) throws QueryException {
-        int or = FRAME.get(constraint);
+    /**
+     * Add a new valid condition to the Frame Constraint.
+     *
+     * @param condition A string representing a valid condition.
+     *        See the synopsis for valid condition names.
+     * @return The {@link FrameConstraint} for chaining.
+     * @throws QueryException
+     */
+    public FrameConstraint add (String condition) throws QueryException {
+        int or = FRAME.get(condition);
         if (or == 0)
             throw new QueryException(706, "Frame type is unknown");
 
@@ -162,11 +218,27 @@
         return this;
     };
 
-    public FrameConstraint or (FrameConstraint constraint) {
+
+    /**
+     * Add new valid conditions to the Frame Constraint.
+     *
+     * @param constraint A Frame constraint representing a set
+     *        of valid conditions.
+     * @return The {@link FrameConstraint} for chaining.
+     */
+    public FrameConstraint add (FrameConstraint constraint) {
         this.vector |= constraint.vector;
         return this;
     };
 
+
+    /**
+     * Invert the condition set of the frame constraint.
+     * All valid conditions become invalid, all invalid
+     * conditions become valid.
+     *
+     * @return The {@link FrameConstraint} for chaining.
+     */
     public FrameConstraint invert () {
         this.vector ^= FRAME_ALL;
         return this;
@@ -174,29 +246,41 @@
 
 
     /**
-     * Check for constraint per bit vector.
+     * Check if a condition is valid.
+     *
+     * @param condition A string representing a condition.
+     *        See the synopsis for valid condition names.
+     * @return A boolean value, indicating if a condition is valid or not.
+     * @throws QueryException
      */
-    public boolean check (int check) {
-        return (this.vector & check) != 0;
-    };
+    public boolean check (String condition) throws QueryException {
+        int check = FRAME.get(condition);
 
-
-    /**
-     * Check for constraint per FrameConstraint.
-     */
-    public boolean check (FrameConstraint check) {
-        return (this.vector & check.vector) != 0;
-    };
-
-
-    /**
-     * Check for constraint per string.
-     */
-    public boolean check (String constraint) throws QueryException {
-        int check = FRAME.get(constraint);
         if (check == 0)
             throw new QueryException(706, "Frame type is unknown");
 
         return this.check(check);
     };
+
+
+    /**
+     * Check if conditions are valid.
+     *
+     * @param conditions An integer bit vector representing a set of conditions.
+     * @return A boolean value, indicating if at least one condition is valid or not.
+     */
+    public boolean check (int conditions) {
+        return (this.vector & conditions) != 0;
+    };
+
+
+    /**
+     * Check if conditions are valid.
+     *
+     * @param conditions A {@link FrameConstraint} representing a set of conditions.
+     * @return A boolean value, indicating if at least one condition is valid or not.
+     */
+    public boolean check (FrameConstraint conditions) {
+        return (this.vector & conditions.vector) != 0;
+    };
 };
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/WithinSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/WithinSpans.java
index 3d88522..c0d32cc 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/WithinSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/WithinSpans.java
@@ -17,9 +17,16 @@
 
 import de.ids_mannheim.korap.query.SpanWithinQuery;
 
+
+/**
+ * SpanWithinQuery is DEPRECATED and will
+ * be replaced by SpanPositionQuery in the near future
+ */
+
 /*
   TODO: Use the flag in KorapQuery!
   TODO: Support exclusivity
+  TODO: Use the term queue and implement it similar to SpanOrQuery
 */
 
 /**
@@ -43,15 +50,15 @@
     boolean nextSpanB = true;
 
     private int
-	wrapStart     = -1,
-	wrapEnd       = -1,
-	embeddedStart = -1,
-	embeddedEnd   = -1,
-	wrapDoc       = -1,
-	embeddedDoc   = -1,
-	matchDoc      = -1,
-	matchStart    = -1,
-	matchEnd      = -1;
+        wrapStart     = -1,
+        wrapEnd       = -1,
+        embeddedStart = -1,
+        embeddedEnd   = -1,
+        wrapDoc       = -1,
+        embeddedDoc   = -1,
+        matchDoc      = -1,
+        matchStart    = -1,
+        matchEnd      = -1;
     
     private Collection<byte[]> matchPayload;
     private Collection<byte[]> embeddedPayload;
@@ -77,13 +84,13 @@
       This may change in case the system switches to 16bit vector
      */
     public static final byte
-	OVERLAP      = (byte) 0,
-	REAL_OVERLAP = (byte) 2,
-	WITHIN       = (byte) 4,
-	REAL_WITHIN  = (byte) 6,
-	ENDSWITH     = (byte) 8,
-	STARTSWITH   = (byte) 10,
-	MATCH        = (byte) 12;
+        OVERLAP      = (byte) 0,
+        REAL_OVERLAP = (byte) 2,
+        WITHIN       = (byte) 4,
+        REAL_WITHIN  = (byte) 6,
+        ENDSWITH     = (byte) 8,
+        STARTSWITH   = (byte) 10,
+        MATCH        = (byte) 12;
 
     private byte flag;
 
@@ -96,41 +103,41 @@
     private boolean tryMatch = true;
 
     private LinkedList<KorapLongSpan>
-	spanStore1,
-	spanStore2;
+        spanStore1,
+        spanStore2;
 
     public WithinSpans (SpanWithinQuery spanWithinQuery,
-			AtomicReaderContext context,
-			Bits acceptDocs,
-			Map<Term,TermContext> termContexts,
-			byte flag) throws IOException {
+                        AtomicReaderContext context,
+                        Bits acceptDocs,
+                        Map<Term,TermContext> termContexts,
+                        byte flag) throws IOException {
 
-	if (DEBUG)
-	    log.trace("Construct WithinSpans");
+        if (DEBUG)
+            log.trace("Construct WithinSpans");
 
-	// Init copies
-	this.matchPayload = new LinkedList<byte[]>();
+        // Init copies
+        this.matchPayload = new LinkedList<byte[]>();
 
-	// Get spans
-	this.wrapSpans = spanWithinQuery.wrap().getSpans(
-	    context,
-	    acceptDocs,
-	    termContexts
-	);
-	this.embeddedSpans = spanWithinQuery.embedded().getSpans(
+        // Get spans
+        this.wrapSpans = spanWithinQuery.wrap().getSpans(
             context,
-	    acceptDocs,
-	    termContexts
-	);
+            acceptDocs,
+            termContexts
+        );
+        this.embeddedSpans = spanWithinQuery.embedded().getSpans(
+            context,
+            acceptDocs,
+            termContexts
+        );
 
-	this.flag = flag;
+        this.flag = flag;
 
-	// SpanStores for backtracking
-	this.spanStore1 = new LinkedList<KorapLongSpan>();
-	this.spanStore2 = new LinkedList<KorapLongSpan>();
+        // SpanStores for backtracking
+        this.spanStore1 = new LinkedList<KorapLongSpan>();
+        this.spanStore2 = new LinkedList<KorapLongSpan>();
 
-	// kept for toString() only.
-	this.query = spanWithinQuery;
+        // kept for toString() only.
+        this.query = spanWithinQuery;
     };
     
 
@@ -138,243 +145,268 @@
     @Override
     public boolean next () throws IOException {
 
-	if (DEBUG)
-	    log.trace("Next with docs {}, {}", wrapDoc, embeddedDoc);
+        if (DEBUG)
+            log.trace("Next with docs {}, {}", wrapDoc, embeddedDoc);
 
-	// Initialize spans
-	if (!this.init()) {
-	    this.more        = false;
-	    this.inSameDoc   = false;
-	    this.wrapDoc     = DocIdSetIterator.NO_MORE_DOCS;
-	    this.embeddedDoc = DocIdSetIterator.NO_MORE_DOCS;
-	    this.matchDoc    = DocIdSetIterator.NO_MORE_DOCS;
-	    return false;
-	};
+        // Initialize spans
+        if (!this.init()) {
+            this.more        = false;
+            this.inSameDoc   = false;
+            this.wrapDoc     = DocIdSetIterator.NO_MORE_DOCS;
+            this.embeddedDoc = DocIdSetIterator.NO_MORE_DOCS;
+            this.matchDoc    = DocIdSetIterator.NO_MORE_DOCS;
+            return false;
+        };
 
-	// There are more spans and they are in the same document
+        // There are more spans and they are in the same document
 
-	while (this.more && (this.inSameDoc || this.toSameDoc())) {
+        while (this.more && (wrapDoc == embeddedDoc ||
+                             // this.inSameDoc ||
+                             this.toSameDoc())) {
+            if (DEBUG)
+                log.trace("We are in the same doc: {}, {}", wrapDoc, embeddedDoc);
 
-	    if (DEBUG)
-		log.trace("We are in the same doc: {}, {}", wrapDoc, embeddedDoc);
+            // Both spans match according to the flag
+            // Silently the next operations are prepared
+            if (this.tryMatch && this.doesMatch()) {
 
-	    // Both spans match according to the flag
-	    // Silently the next operations are prepared
-	    if (this.tryMatch && this.doesMatch()) {
-
-		if (this.wrapEnd == -1)
-		    this.wrapEnd = this.wrapSpans.end();
+                if (this.wrapEnd == -1)
+                    this.wrapEnd = this.wrapSpans.end();
 		
-		this.matchStart = embeddedStart < wrapStart ? embeddedStart : wrapStart;
-		this.matchEnd   = embeddedEnd   > wrapEnd   ? embeddedEnd   : wrapEnd;
-		this.matchDoc   = embeddedDoc;
-		this.matchPayload.clear();
+                this.matchStart = embeddedStart < wrapStart ? embeddedStart : wrapStart;
+                this.matchEnd   = embeddedEnd   > wrapEnd   ? embeddedEnd   : wrapEnd;
+                this.matchDoc   = embeddedDoc;
+                this.matchPayload.clear();
 
-		if (this.embeddedPayload != null)
-		    matchPayload.addAll(embeddedPayload);
+                if (this.embeddedPayload != null)
+                    matchPayload.addAll(embeddedPayload);
 
-		if (this.wrapSpans.isPayloadAvailable())
-		    this.matchPayload.addAll(wrapSpans.getPayload());
+                if (this.wrapSpans.isPayloadAvailable())
+                    this.matchPayload.addAll(wrapSpans.getPayload());
 
-		if (DEBUG)
-		    log.trace("   ---- MATCH ---- {}-{} ({})", matchStart, matchEnd, matchDoc);
+                if (DEBUG)
+                    log.trace(
+                        "   ---- MATCH ---- {}-{} ({})",
+                        matchStart,
+                        matchEnd,
+                        matchDoc
+                    );
 
-		this.tryMatch = false;
-		return true;
-	    }
+                this.tryMatch = false;
+                return true;
+            }
 
-	    // Get next embedded
-	    else if (this.nextSpanB) {
+            // Get next embedded
+            else if (this.nextSpanB) {
 
-		// Next time try the match
-		this.tryMatch = true;
+                // Next time try the match
+                this.tryMatch = true;
 		
-		if (DEBUG)
-		    log.trace("In the next embedded branch");
+                if (DEBUG)
+                    log.trace("In the next embedded branch");
 		
-		// There is nothing in the second store
-		if (this.spanStore2.isEmpty()) {
-		    if (DEBUG)
-			log.trace("SpanStore 2 is empty");
-		  
-		    // Forward with embedding
-		    if (!this.embeddedSpans.next()) {
-			this.nextSpanA();
-			continue;
-		    }
+                KorapLongSpan current = null;
 
-		    else if (DEBUG) {
-			log.trace("Fetch next embedded span");
-		    };
+                // New - fetch until theres a span in the correct doc or bigger
+                while (!this.spanStore2.isEmpty()) {
+                    current = spanStore2.removeFirst();
+                    if (current.doc >= this.wrapDoc)
+                        break;
+                };
+
+
+                // There is nothing in the second store
+                if (current == null) {
+                    if (DEBUG)
+                        log.trace("SpanStore 2 is empty");
+                    
+                    // Forward with embedding
+                    if (!this.embeddedSpans.next()) {
+                        this.nextSpanA();
+                        continue;
+                    }
+
+                    else if (DEBUG) {
+                        log.trace("Fetch next embedded span");
+                    };
 		    
-		    this.embeddedStart = -1;
-		    this.embeddedEnd = -1;
-		    this.embeddedPayload = null;
-		    this.embeddedDoc = this.embeddedSpans.doc();
+                    this.embeddedStart = -1;
+                    this.embeddedEnd = -1;
+                    this.embeddedPayload = null;
+                    this.embeddedDoc = this.embeddedSpans.doc();
 
-		    if (this.embeddedDoc != this.wrapDoc) {
-
-			this.tryMatch = false;
-
-			if (DEBUG) {
-			    log.trace("Embedded span is in a new document {}",
-				      _currentEmbedded().toString());
-			    log.trace("Reset current embedded doc");
-			};	
+                    if (this.embeddedDoc != this.wrapDoc) {
+                        
+                        if (DEBUG) {
+                            log.trace("Embedded span is in a new document {}",
+                                      _currentEmbedded().toString());
+                            log.trace("Reset current embedded doc");
+                        };	
 	
-			this.embeddedDoc = wrapDoc;
-			this.inSameDoc = true;
-			this.nextSpanA();
-			continue;
-		    };
-		    
-		    if (DEBUG)
-			log.trace(
-			    "   Forward embedded span to {}",
-			    _currentEmbedded().toString()
-			);
+                        /*
+                        if (DEBUG)
+                            log.trace("Clear all span stores");
+                        this.spanStore1.clear();
+                        this.spanStore2.clear();
+                        */
 
-		    if (this.embeddedDoc != this.wrapDoc) {
-			if (DEBUG)
-			    log.trace("Delete all span stores");
+                        this.storeEmbedded();
+
+                        // That is necessary to backtrack to the last document!
+                        this.inSameDoc = true;
+                        this.embeddedDoc = wrapDoc;
+                        // this.tryMatch = false; // already covered in nextSpanA
+
+                        this.nextSpanA();
+                        continue;
+                    };
+		    
+                    if (DEBUG)
+                        log.trace(
+                            "   Forward embedded span to {}",
+                            _currentEmbedded().toString()
+                        );
+                    
+                    if (this.embeddedDoc != this.wrapDoc) {
+                        if (DEBUG)
+                            log.trace("Delete all span stores");
+                     
+                        // Is this always a good idea?
+                        /*
+                        this.spanStore1.clear();
+                        this.spanStore2.clear();
+                        */
+
+                        this.embeddedStart = -1;
+                        this.embeddedEnd = -1;
+                        this.embeddedPayload = null;
 			
-			this.spanStore1.clear();
-			this.spanStore2.clear();
+                        if (!this.toSameDoc()) {
+                            this.more = false;
+                            this.inSameDoc = false;
+                            return false;
+                        };
+                    };
 
-			this.embeddedStart = -1;
-			this.embeddedEnd = -1;
-			this.embeddedPayload = null;
-			
-			if (!this.toSameDoc()) {
-			    this.more = false;
-			    this.inSameDoc = false;
-			    return false;
-			};
-		    };
-
-		    this.more = true;
-		    this.inSameDoc = true;
-		    this.tryMatch = true;
+                    this.more = true;
+                    this.inSameDoc = true;
+                    this.tryMatch = true;
 		    
-		    this.nextSpanB();
-		    continue;
-		}
+                    this.nextSpanB();
+                    continue;
+                }
 		
-		// Fetch from second store?
-		else {
-		    /** TODO: Change this to a single embedded object! */
-	
-		    KorapLongSpan current = spanStore2.removeFirst();
-		    this.embeddedStart = current.start;
-		    this.embeddedEnd = current.end;
-		    this.embeddedDoc = current.doc;
+                // Fetch from second store?
+                else {
+                    /** TODO: Change this to a single embedded object! */
+                    this.embeddedStart = current.start;
+                    this.embeddedEnd = current.end;
+                    this.embeddedDoc = current.doc;
 
-		    if (current.payload != null) {
-			this.embeddedPayload = new ArrayList<byte[]>(current.payload.size());
-			this.embeddedPayload.addAll(current.payload);
-		    }
-		    else {
-			this.embeddedPayload = null;
-		    };
+                    if (current.payload != null) {
+                        this.embeddedPayload = new ArrayList<byte[]>(current.payload.size());
+                        this.embeddedPayload.addAll(current.payload);
+                    }
+                    else {
+                        this.embeddedPayload = null;
+                    };
 
-		    if (DEBUG)
-			log.trace("Fetch current from SpanStore 2: {}", current.toString());
+                    if (DEBUG)
+                        log.trace("Fetch current from SpanStore 2: {}", current.toString());
 		    
-		    this.tryMatch = true;
-		};
-		continue;
-	    };
+                    this.tryMatch = true;
+                };
+                continue;
+            };
 
-	    // get next wrap
-	    if (DEBUG)
-		log.trace("In the next wrap branch");
+            // get next wrap
+            if (DEBUG)
+                log.trace("In the next wrap branch");
 
-	    this.tryMatch = true;
+            this.tryMatch = true;
 
-	    if (DEBUG)
-		log.trace("Try next wrap");
+            if (DEBUG)
+                log.trace("Try next wrap");
 
-	    // shift the stored spans
-	    if (!this.spanStore1.isEmpty()) {
-		if (DEBUG) {
-		    log.trace("Move everything from SpanStore 1 to SpanStore 2:");
-		    for (KorapLongSpan i : this.spanStore1) {
-			log.trace("     | {}", i.toString());
-		    };
-		};
+            // shift the stored spans
+            if (!this.spanStore1.isEmpty()) {
+                if (DEBUG) {
+                    log.trace("Move everything from SpanStore 1 to SpanStore 2:");
+                    for (KorapLongSpan i : this.spanStore1) {
+                        log.trace("     | {}", i.toString());
+                    };
+                };
 
-		// Move everything to spanStore2
-		this.spanStore2.addAll(
-		    0,
-		    (LinkedList<KorapLongSpan>) this.spanStore1.clone()
-	        );
-		this.spanStore1.clear();
+                // Move everything to spanStore2
+                this.spanStore2.addAll(
+                    0,
+                    (LinkedList<KorapLongSpan>) this.spanStore1.clone()
+                );
+                this.spanStore1.clear();
 
-		if (DEBUG) {
-		    log.trace("SpanStore 2 now is:");
-		    for (KorapLongSpan i : this.spanStore2) {
-			log.trace("     | {}", i.toString());
-		    };
-		};
+                if (DEBUG) {
+                    log.trace("SpanStore 2 now is:");
+                    for (KorapLongSpan i : this.spanStore2) {
+                        log.trace("     | {}", i.toString());
+                    };
+                };
+                
+            }
+            else if (DEBUG) {
+                log.trace("spanStore 1 is empty");
+            };
 
-	    }
-	    else if (DEBUG) {
-		log.trace("spanStore 1 is empty");
-	    };
+            // Get next wrap
+            if (this.wrapSpans.next()) {
 
-	    // Get next wrap
-	    if (this.wrapSpans.next()) {
-
-		// Reset wrapping information
-		this.wrapStart = -1;
-		this.wrapEnd = -1;
+                // Reset wrapping information
+                this.wrapStart = -1;
+                this.wrapEnd = -1;
 		
-		// Retrieve doc information
-		this.wrapDoc = this.wrapSpans.doc();
+                // Retrieve doc information
+                this.wrapDoc = this.wrapSpans.doc();
 
-		if (DEBUG)
-		    log.trace(
-		        "   Forward wrap span to {}",
-			_currentWrap().toString()
-		    );
+                if (DEBUG)
+                    log.trace(
+                        "   Forward wrap span to {}",
+                        _currentWrap().toString()
+                    );
 
-		    
-		if (this.embeddedDoc != this.wrapDoc) {
-		    if (DEBUG)
-			log.trace("Delete all span stores");
-			
-		    this.spanStore1.clear();
-		    this.spanStore2.clear();
+                if (this.embeddedDoc != this.wrapDoc) {
+                    if (DEBUG)
+                        log.trace("Delete all span stores");
+                    this.spanStore1.clear();
+                    this.spanStore2.clear();
 
-		    // Reset embedded:
-		    this.embeddedStart = -1;
-		    this.embeddedEnd = -1;
-		    this.embeddedPayload = null;
+                    // Reset embedded:
+                    this.embeddedStart = -1;
+                    this.embeddedEnd = -1;
+                    this.embeddedPayload = null;
 
-		    if (!this.toSameDoc()) {
-			this.inSameDoc = false;
-			this.more = false;
-			return false;
-		    };
-		}
-		else {
-		    this.inSameDoc = true;
-		    // Do not match with the current state
-		    this.tryMatch = false;
-		};
-		
-		this.nextSpanB();
-		continue;
-	    }
-	    this.more = false;
-	    this.inSameDoc = false;
-	    this.spanStore1.clear();
-	    this.spanStore2.clear();
-	    return false;
-	};
+                    if (!this.toSameDoc()) {
+                        this.inSameDoc = false;
+                        this.more = false;
+                        return false;
+                    };
+                }
+                else {
+                    this.inSameDoc = true;
+                    // Do not match with the current state
+                    this.tryMatch = false;
+                };
+                
+                this.nextSpanB();
+                continue;
+            }
+            this.more = false;
+            this.inSameDoc = false;
+            this.spanStore1.clear();
+            this.spanStore2.clear();
+            return false;
+        };
 
-	// No more matches
-	return false;
+        // No more matches
+        return false;
     };
 
 
@@ -383,141 +415,154 @@
      */
     private boolean toSameDoc () throws IOException {
 
-	if (DEBUG)
-	    log.trace("Forward to find same docs");
+        if (DEBUG)
+            log.trace("Forward to find same docs");
 
-	this.more = true;
-	this.inSameDoc = true;
+        /*
+        if (this.embeddedSpans == null) {
+            this.more      = false;
+            this.matchDoc  = DocIdSetIterator.NO_MORE_DOCS;
+            this.inSameDoc = false;
+            return false;
+        };
+        */
 
-	this.wrapDoc     = this.wrapSpans.doc();
-	this.embeddedDoc = this.embeddedSpans.doc();
+        this.more = true;
+        this.inSameDoc = true;
 
-	// Clear all spanStores
-	if (this.wrapDoc != this.embeddedDoc) {
-	    this.spanStore1.clear();
-	    this.spanStore2.clear();
-	}
+        this.wrapDoc     = this.wrapSpans.doc();
+        this.embeddedDoc = this.embeddedSpans.doc();
 
-	// Last doc was reached
-	else if (this.wrapDoc == DocIdSetIterator.NO_MORE_DOCS) {
-	    this.more      = false;
-	    this.matchDoc  = DocIdSetIterator.NO_MORE_DOCS;
-	    this.inSameDoc = false;
-	    return false;
-	}
-	else {
-	    if (DEBUG)  {
-		log.trace("Current position already is in the same doc");
-		log.trace("Embedded: {}", _currentEmbedded().toString());
-	    };
-	    return true;
-	};
+        // Clear all spanStores
+        if (this.wrapDoc != this.embeddedDoc) {
+            /*
+            if (DEBUG)
+                log.trace("Clear all spanStores when moving forward");
+            // Why??
+            this.spanStore1.clear();
+            this.spanStore2.clear();
+            */
+        }
 
-	// Forward till match
-	while (this.wrapDoc != this.embeddedDoc) {
+        // Last doc was reached
+        else if (this.wrapDoc == DocIdSetIterator.NO_MORE_DOCS) {
+            this.more      = false;
+            this.matchDoc  = DocIdSetIterator.NO_MORE_DOCS;
+            this.inSameDoc = false;
+            return false;
+        }
+        else {
+            if (DEBUG)  {
+                log.trace("Current position already is in the same doc");
+                log.trace("Embedded: {}", _currentEmbedded().toString());
+            };
+            return true;
+        };
 
-	    // Forward wrapInfo
-	    if (this.wrapDoc < this.embeddedDoc) {
+        // Forward till match
+        while (this.wrapDoc != this.embeddedDoc) {
 
-		// Set document information
-		if (!wrapSpans.skipTo(this.embeddedDoc)) {
-		    this.more = false;
-		    this.inSameDoc = false;
-		    return false;
-		};
+            // Forward wrapInfo
+            if (this.wrapDoc < this.embeddedDoc) {
 
-		if (DEBUG)
-		    log.trace("Skip wrap to doc {}", this.embeddedDoc);
+                // Set document information
+                if (!wrapSpans.skipTo(this.embeddedDoc)) {
+                    this.more = false;
+                    this.inSameDoc = false;
+                    return false;
+                };
+                
+                if (DEBUG)
+                    log.trace("Skip wrap to doc {}", this.embeddedDoc);
 		
-		this.wrapDoc = this.wrapSpans.doc();
-
-		if (wrapDoc == DocIdSetIterator.NO_MORE_DOCS) {
-		    this.more = false;
-		    this.inSameDoc = false;
-		    this.embeddedDoc = DocIdSetIterator.NO_MORE_DOCS;
-		    this.matchDoc = DocIdSetIterator.NO_MORE_DOCS;
-		    return false;
-		};
+                this.wrapDoc = this.wrapSpans.doc();
+                
+                if (wrapDoc == DocIdSetIterator.NO_MORE_DOCS) {
+                    this.more = false;
+                    this.inSameDoc = false;
+                    this.embeddedDoc = DocIdSetIterator.NO_MORE_DOCS;
+                    this.matchDoc = DocIdSetIterator.NO_MORE_DOCS;
+                    return false;
+                };
 		
-		this.wrapStart = -1;
-		this.wrapEnd   = -1;
-		
-		if (wrapDoc == embeddedDoc)
-		    return true;
-
-	    }
+                this.wrapStart = -1;
+                this.wrapEnd   = -1;
+                
+                if (wrapDoc == embeddedDoc)
+                    return true;
+                
+            }
 	
-	    // Forward embedInfo
-	    else if (this.wrapDoc > this.embeddedDoc) {
-
-		// Set document information
-		if (!this.embeddedSpans.skipTo(this.wrapDoc)) {
-		    this.more = false;
-		    this.inSameDoc = false;
-		    return false;
-		};
-
-		if (DEBUG)
-		    log.trace("Skip embedded to doc {}", this.wrapDoc);
-
-		this.embeddedDoc = this.embeddedSpans.doc();
-
-		if (this.embeddedDoc == DocIdSetIterator.NO_MORE_DOCS) {
-		    this.more      = false;
-		    this.inSameDoc = false;
-		    this.wrapDoc   = DocIdSetIterator.NO_MORE_DOCS;
-		    this.matchDoc  = DocIdSetIterator.NO_MORE_DOCS;
-		    return false;
-		};
-		
-		this.embeddedStart = -1;
-		this.embeddedEnd = -1;
-		this.embeddedPayload = null;
-	
-		if (this.wrapDoc == this.embeddedDoc)
-		    return true;
-	    }
-	    else {
-		return false;
-	    };
-	};
-	
-	return true;
+            // Forward embedInfo
+            else if (this.wrapDoc > this.embeddedDoc) {
+                
+                // Set document information
+                if (!this.embeddedSpans.skipTo(this.wrapDoc)) {
+                    this.more = false;
+                    this.inSameDoc = false;
+                    return false;
+                };
+                
+                if (DEBUG)
+                    log.trace("Skip embedded to doc {}", this.wrapDoc);
+                
+                this.embeddedDoc = this.embeddedSpans.doc();
+                
+                if (this.embeddedDoc == DocIdSetIterator.NO_MORE_DOCS) {
+                    this.more      = false;
+                    this.inSameDoc = false;
+                    this.wrapDoc   = DocIdSetIterator.NO_MORE_DOCS;
+                    this.matchDoc  = DocIdSetIterator.NO_MORE_DOCS;
+                    return false;
+                };
+                
+                this.embeddedStart = -1;
+                this.embeddedEnd = -1;
+                this.embeddedPayload = null;
+                
+                if (this.wrapDoc == this.embeddedDoc)
+                    return true;
+            }
+            else {
+                return false;
+            };
+        };
+        
+        return true;
     };
 
 
     // Initialize spans
     private boolean init () throws IOException {
 
-	// There is a missing span
-	if (this.embeddedDoc >= 0)
-	    return true;
+        // There is a missing span
+        if (this.embeddedDoc >= 0)
+            return true;
 
-	if (DEBUG)
-	    log.trace("Initialize spans");
+        if (DEBUG)
+            log.trace("Initialize spans");
 
-	// First tick for both spans
-	if (!(this.embeddedSpans.next() && this.wrapSpans.next())) {
+        // First tick for both spans
+        if (!(this.embeddedSpans.next() && this.wrapSpans.next())) {
 
-	    if (DEBUG)
-		log.trace("No spans initialized");
+            if (DEBUG)
+                log.trace("No spans initialized");
 	    
-	    this.embeddedDoc = -1;
-	    this.more = false;
-	    return false;
-	};
-	this.more = true;
+            this.embeddedDoc = -1;
+            this.more = false;
+            return false;
+        };
+        this.more = true;
 
-	// Store current positions for wrapping and embedded spans
-	this.wrapDoc     = this.wrapSpans.doc();
-	this.embeddedDoc = this.embeddedSpans.doc();
+        // Store current positions for wrapping and embedded spans
+        this.wrapDoc     = this.wrapSpans.doc();
+        this.embeddedDoc = this.embeddedSpans.doc();
 
-
-	// Set inSameDoc to true, if it is true
-	if (this.embeddedDoc == this.wrapDoc)
-	    this.inSameDoc = true;
+        // Set inSameDoc to true, if it is true
+        if (this.embeddedDoc == this.wrapDoc)
+            this.inSameDoc = true;
 	
-	return true;
+        return true;
     };
 
 
@@ -536,48 +581,48 @@
      */
     public boolean skipTo (int target) throws IOException {
 
-	if (DEBUG)
-	    log.trace("skipTo document {}", target);
+        if (DEBUG)
+            log.trace("skipTo document {}", target);
 
-	// Initialize spans
-	if (!this.init())
-	    return false;
+        // Initialize spans
+        if (!this.init())
+            return false;
 
-	assert target > embeddedDoc;
+        assert target > embeddedDoc;
 
-	// Only forward embedded spans
-	if (this.more && (this.embeddedDoc < target)) {
-	    if (this.embeddedSpans.skipTo(target)) {
-		this.inSameDoc = false;
-		this.embeddedStart = -1;
-		this.embeddedEnd = -1;
-		this.embeddedPayload = null;
-		this.embeddedDoc = this.embeddedSpans.doc();
-	    }
+        // Only forward embedded spans
+        if (this.more && (this.embeddedDoc < target)) {
+            if (this.embeddedSpans.skipTo(target)) {
+                this.inSameDoc = false;
+                this.embeddedStart = -1;
+                this.embeddedEnd = -1;
+                this.embeddedPayload = null;
+                this.embeddedDoc = this.embeddedSpans.doc();
+            }
 
-	    // Can't be skipped to target
-	    else {
-		this.inSameDoc = false;
-		this.more = false;
-		return false;
-	    };
-	};
+            // Can't be skipped to target
+            else {
+                this.inSameDoc = false;
+                this.more = false;
+                return false;
+            };
+        };
 
-	// Move to same doc
-	return this.toSameDoc();
+        // Move to same doc
+        return this.toSameDoc();
     };
 
     private void nextSpanA () {
-	if (DEBUG)
-	    log.trace("Try wrap next time");
-	this.tryMatch = false;
-	this.nextSpanB = false;
+        if (DEBUG)
+            log.trace("Try wrap next time");
+        this.tryMatch = false;
+        this.nextSpanB = false;
     };
 
     private void nextSpanB () {
-	if (DEBUG)
-	    log.trace("Try embedded next time");
-	this.nextSpanB = true;
+        if (DEBUG)
+            log.trace("Try embedded next time");
+        this.nextSpanB = true;
     };
 
 
@@ -746,19 +791,22 @@
     
 
     private KorapLongSpan _currentWrap () {
-	KorapLongSpan _wrap = new KorapLongSpan();
-	_wrap.start = this.wrapStart != -1 ? this.wrapStart : this.wrapSpans.start();
-	_wrap.end   = this.wrapEnd   != -1 ? this.wrapEnd   : this.wrapSpans.end();
-	_wrap.doc   = this.wrapDoc   != -1 ? this.wrapDoc   : this.wrapSpans.doc();
-	return _wrap;
+        KorapLongSpan _wrap = new KorapLongSpan();
+        _wrap.start = this.wrapStart != -1 ? this.wrapStart : this.wrapSpans.start();
+        _wrap.end   = this.wrapEnd   != -1 ? this.wrapEnd   : this.wrapSpans.end();
+        _wrap.doc   = this.wrapDoc   != -1 ? this.wrapDoc   : this.wrapSpans.doc();
+        return _wrap;
     };
 	    
     private KorapLongSpan _currentEmbedded () {
-	KorapLongSpan _embedded = new KorapLongSpan();
-	_embedded.start = this.embeddedStart != -1 ? this.embeddedStart : this.embeddedSpans.start();
-	_embedded.end   = this.embeddedEnd   != -1 ? this.embeddedEnd   : this.embeddedSpans.end();
-	_embedded.doc   = this.embeddedDoc   != -1 ? this.embeddedDoc   : this.embeddedSpans.doc();
-	return _embedded;
+        KorapLongSpan _embedded = new KorapLongSpan();
+        _embedded.start = this.embeddedStart != -1 ?
+                          this.embeddedStart : this.embeddedSpans.start();
+        _embedded.end   = this.embeddedEnd   != -1 ?
+                          this.embeddedEnd   : this.embeddedSpans.end();
+        _embedded.doc   = this.embeddedDoc   != -1 ?
+                          this.embeddedDoc   : this.embeddedSpans.doc();
+        return _embedded;
     };
     
 
@@ -787,23 +835,23 @@
 
 	// Case 3, 4, 5, 8
 	else if (currentCase <= (byte) 5 ||
-		 currentCase == (byte) 8) {
+             currentCase == (byte) 8) {
 	    if (flag <= 2)
-		this.storeEmbedded();
+            this.storeEmbedded();
 	    this.nextSpanB();
 	}
 
 	// Case 11
 	else if (currentCase == (byte) 11) {
 	    if (this.flag == REAL_WITHIN) {
-		this.nextSpanB();
+            this.nextSpanB();
 	    }
 	    else if (this.flag >= STARTSWITH) {
-		this.nextSpanA();
+            this.nextSpanA();
 	    }
 	    else {
-		this.storeEmbedded();
-		this.nextSpanB();
+            this.storeEmbedded();
+            this.nextSpanB();
 	    };
 	}
 
@@ -830,33 +878,35 @@
 	};
     };
 
-    // Store the current embedded span in the second spanStore
+    // Store the current embedded span in the first spanStore
     private void storeEmbedded () throws IOException {
 
-	// Create a current copy
-	KorapLongSpan embedded = new KorapLongSpan();
-	embedded.start = this.embeddedStart != -1 ? this.embeddedStart : this.embeddedSpans.start();
-	embedded.end   = this.embeddedEnd   != -1 ? this.embeddedEnd : this.embeddedSpans.end();
-	embedded.doc   = this.embeddedDoc;
+        // Create a current copy
+        KorapLongSpan embedded = new KorapLongSpan();
+        embedded.start = this.embeddedStart != -1 ?
+                         this.embeddedStart : this.embeddedSpans.start();
+        embedded.end   = this.embeddedEnd   != -1 ?
+                         this.embeddedEnd : this.embeddedSpans.end();
+        embedded.doc   = this.embeddedDoc;
 
-	// Copy payloads
-	if (this.embeddedPayload != null) {
-	    embedded.payload = new ArrayList<byte[]>(this.embeddedPayload.size());
-	    embedded.payload.addAll(this.embeddedPayload);
-	}
-	else if (this.embeddedSpans.isPayloadAvailable()) {
-	    embedded.payload = new ArrayList<byte[]>(3);
-	    Collection<byte[]> payload = this.embeddedSpans.getPayload();
+        // Copy payloads
+        if (this.embeddedPayload != null) {
+            embedded.payload = new ArrayList<byte[]>(this.embeddedPayload.size());
+            embedded.payload.addAll(this.embeddedPayload);
+        }
+        else if (this.embeddedSpans.isPayloadAvailable()) {
+            embedded.payload = new ArrayList<byte[]>(3);
+            Collection<byte[]> payload = this.embeddedSpans.getPayload();
+            
+            this.embeddedPayload = new ArrayList<byte[]>(payload.size());
+            this.embeddedPayload.addAll(payload);
+            embedded.payload.addAll(payload);
+        };
 
-	    this.embeddedPayload = new ArrayList<byte[]>(payload.size());
-	    this.embeddedPayload.addAll(payload);
-	    embedded.payload.addAll(payload);
-	};
+        this.spanStore1.add(embedded);
 
-	this.spanStore1.add(embedded);
-
-	if (DEBUG)
-	    log.trace("Pushed to spanStore 1 {} (in storeEmbedded)", embedded.toString());
+        if (DEBUG)
+            log.trace("Pushed to spanStore 1 {} (in storeEmbedded)", embedded.toString());
     };
     
 
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestWithinIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestWithinIndex.java
index 8f63b62..bf86f29 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestWithinIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestWithinIndex.java
@@ -34,6 +34,11 @@
 
 // mvn -Dtest=TestWithinIndex#indexExample1 test
 
+
+/**
+ * @author diewald
+ * @author margaretha
+ */
 @RunWith(JUnit4.class)
 public class TestWithinIndex {
 
@@ -41,1074 +46,1073 @@
 
     @Test
     public void indexExample1a () throws IOException {
-	KorapIndex ki = new KorapIndex();
+        KorapIndex ki = new KorapIndex();
 
-	// <a>x<a>y<a>zhij</a>hij</a>hij</a>
-	FieldDocument fd = new FieldDocument();
-	fd.addTV("base",
-		 "x   y   z   h   i   j   h   i   j   h   i   j   ",
-		 "[(0-3)s:x|<>:a#0-36$<i>12]" + // 1
-		 "[(3-6)s:y|<>:a#3-27$<i>9]" +  // 2
-		 "[(6-9)s:z|<>:a#6-18$<i>6]" +  // 3
-		 "[(9-12)s:h]" +   // 4
-		 "[(12-15)s:i]" +  // 5
-		 "[(15-18)s:j]" +  // 6
-		 "[(18-21)s:h]" +  // 7
-		 "[(21-24)s:i]" +  // 8
-		 "[(24-27)s:j]" +  // 9
-		 "[(27-30)s:h]" +  // 10
-		 "[(30-33)s:i]" +  // 11
-		 "[(33-36)s:j]");  // 12
-	ki.addDoc(fd);
+        // <a>x<a>y<a>zhij</a>hij</a>hij</a>
+        FieldDocument fd = new FieldDocument();
+        fd.addTV("base",
+                 "x   y   z   h   i   j   h   i   j   h   i   j   ",
+                 "[(0-3)s:x|<>:a#0-36$<i>12]" + // 1
+                 "[(3-6)s:y|<>:a#3-27$<i>9]" +  // 2
+                 "[(6-9)s:z|<>:a#6-18$<i>6]" +  // 3
+                 "[(9-12)s:h]" +   // 4
+                 "[(12-15)s:i]" +  // 5
+                 "[(15-18)s:j]" +  // 6
+                 "[(18-21)s:h]" +  // 7
+                 "[(21-24)s:i]" +  // 8
+                 "[(24-27)s:j]" +  // 9
+                 "[(27-30)s:h]" +  // 10
+                 "[(30-33)s:i]" +  // 11
+                 "[(33-36)s:j]");  // 12
+        ki.addDoc(fd);
 
-	ki.commit();
+        ki.commit();
 
-	SpanQuery sq;
-	KorapResult kr;
+        SpanQuery sq;
+        KorapResult kr;
 
-	sq = new SpanWithinQuery(
-	    new SpanElementQuery("base", "a"),
+        sq = new SpanWithinQuery(
+            new SpanElementQuery("base", "a"),
             new SpanTermQuery(new Term("base", "s:h"))
         );
 
-	kr = ki.search(sq, (short) 10);
+        kr = ki.search(sq, (short) 10);
 	
-	assertEquals("totalResults", kr.getTotalResults(), 6);
+        assertEquals("totalResults", kr.getTotalResults(), 6);
 
-	assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
-	assertEquals("EndPos (0)", 12, kr.getMatch(0).endPos);
-	assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
-	assertEquals("EndPos (1)", 12, kr.getMatch(1).endPos);
-	assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
-	assertEquals("EndPos (2)", 12, kr.getMatch(2).endPos);
-	assertEquals("StartPos (3)", 1, kr.getMatch(3).startPos);
-	assertEquals("EndPos (3)", 9, kr.getMatch(3).endPos);
-	assertEquals("StartPos (4)", 1, kr.getMatch(4).startPos);
-	assertEquals("EndPos (4)", 9, kr.getMatch(4).endPos);
-	assertEquals("StartPos (5)", 2, kr.getMatch(5).startPos);
-	assertEquals("EndPos (5)", 6, kr.getMatch(5).endPos);
-
-	assertEquals(1, ki.numberOf("documents"));
+        assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
+        assertEquals("EndPos (0)", 12, kr.getMatch(0).endPos);
+        assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
+        assertEquals("EndPos (1)", 12, kr.getMatch(1).endPos);
+        assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
+        assertEquals("EndPos (2)", 12, kr.getMatch(2).endPos);
+        assertEquals("StartPos (3)", 1, kr.getMatch(3).startPos);
+        assertEquals("EndPos (3)", 9, kr.getMatch(3).endPos);
+        assertEquals("StartPos (4)", 1, kr.getMatch(4).startPos);
+        assertEquals("EndPos (4)", 9, kr.getMatch(4).endPos);
+        assertEquals("StartPos (5)", 2, kr.getMatch(5).startPos);
+        assertEquals("EndPos (5)", 6, kr.getMatch(5).endPos);
+        
+        assertEquals(1, ki.numberOf("documents"));
     };
 
     @Test
     public void indexExample1b () throws IOException {
-	// Cases 9, 12, 13
-	KorapIndex ki = new KorapIndex();
+        // Cases 9, 12, 13
+        KorapIndex ki = new KorapIndex();
 
-	// <a>x<a>y<a>zhij</a>hij</a>hij</a>
-	FieldDocument fd = new FieldDocument();
-	fd.addTV("base",
-		 "x   y   z   h   i   j   h   i   j   h   i   j   ",
-		 "[(0-3)s:x|<>:a#0-36$<i>12]" + // 1
-		 "[(3-6)s:y|<>:a#3-27$<i>9]" +  // 2
-		 "[(6-9)s:z|<>:a#6-18$<i>6]" +  // 3
-		 "[(9-12)s:h]" +   // 4
-		 "[(12-15)s:i]" +  // 5
-		 "[(15-18)s:j]" +  // 6
-		 "[(18-21)s:h]" +  // 7
-		 "[(21-24)s:i]" +  // 8
-		 "[(24-27)s:j]" +  // 9
-		 "[(27-30)s:h]" +  // 10
-		 "[(30-33)s:i]" +  // 11
-		 "[(33-36)s:j]");  // 12
-	ki.addDoc(fd);
+        // <a>x<a>y<a>zhij</a>hij</a>hij</a>
+        FieldDocument fd = new FieldDocument();
+        fd.addTV("base",
+                 "x   y   z   h   i   j   h   i   j   h   i   j   ",
+                 "[(0-3)s:x|<>:a#0-36$<i>12]" + // 1
+                 "[(3-6)s:y|<>:a#3-27$<i>9]" +  // 2
+                 "[(6-9)s:z|<>:a#6-18$<i>6]" +  // 3
+                 "[(9-12)s:h]" +   // 4
+                 "[(12-15)s:i]" +  // 5
+                 "[(15-18)s:j]" +  // 6
+                 "[(18-21)s:h]" +  // 7
+                 "[(21-24)s:i]" +  // 8
+                 "[(24-27)s:j]" +  // 9
+                 "[(27-30)s:h]" +  // 10
+                 "[(30-33)s:i]" +  // 11
+                 "[(33-36)s:j]");  // 12
+        ki.addDoc(fd);
 
-	// <a>x<a>y<a>zhij</a>hij</a>hij</a>
-	fd = new FieldDocument();
-	fd.addTV("base",
-		 "x   y   z   h   i   j   h   i   j   h   i   j   ",
-		 "[(0-3)s:x|<>:a#0-36$<i>12]" + // 1
-		 "[(3-6)s:y|<>:a#3-27$<i>9]" +  // 2
-		 "[(6-9)s:z|<>:a#6-18$<i>6]" +  // 3
-		 "[(9-12)s:h]" +   // 4
-		 "[(12-15)s:i]" +  // 5
-		 "[(15-18)s:j]" +  // 6
-		 "[(18-21)s:h]" +  // 7
-		 "[(21-24)s:i]" +  // 8
-		 "[(24-27)s:j]" +  // 9
-		 "[(27-30)s:h]" +  // 10
-		 "[(30-33)s:i]" +  // 11
-		 "[(33-36)s:j]");  // 12
-	ki.addDoc(fd);
+        // <a>x<a>y<a>zhij</a>hij</a>hij</a>
+        fd = new FieldDocument();
+        fd.addTV("base",
+                 "x   y   z   h   i   j   h   i   j   h   i   j   ",
+                 "[(0-3)s:x|<>:a#0-36$<i>12]" + // 1
+                 "[(3-6)s:y|<>:a#3-27$<i>9]" +  // 2
+                 "[(6-9)s:z|<>:a#6-18$<i>6]" +  // 3
+                 "[(9-12)s:h]" +   // 4
+                 "[(12-15)s:i]" +  // 5
+                 "[(15-18)s:j]" +  // 6
+                 "[(18-21)s:h]" +  // 7
+                 "[(21-24)s:i]" +  // 8
+                 "[(24-27)s:j]" +  // 9
+                 "[(27-30)s:h]" +  // 10
+                 "[(30-33)s:i]" +  // 11
+                 "[(33-36)s:j]");  // 12
+        ki.addDoc(fd);
 
 
-	// Save documents
-	ki.commit();
+        // Save documents
+        ki.commit();
+        
+        SpanQuery sq;
+        KorapResult kr;
 
-	SpanQuery sq;
-	KorapResult kr;
-
-	sq = new SpanWithinQuery(
-	    new SpanElementQuery("base", "a"),
+        sq = new SpanWithinQuery(
+            new SpanElementQuery("base", "a"),
             new SpanTermQuery(new Term("base", "s:h"))
         );
 
-	kr = ki.search(sq, (short) 15);
+        kr = ki.search(sq, (short) 15);
 	
-	assertEquals("totalResults", kr.getTotalResults(), 12);
+        assertEquals("totalResults", kr.getTotalResults(), 12);
 	
-	assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
-	assertEquals("EndPos (0)", 12, kr.getMatch(0).endPos);
-	assertEquals("Doc (0)", 0, kr.getMatch(0).internalDocID);
-	assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
-	assertEquals("EndPos (1)", 12, kr.getMatch(1).endPos);
-	assertEquals("Doc (1)", 0, kr.getMatch(1).internalDocID);
-	assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
-	assertEquals("EndPos (2)", 12, kr.getMatch(2).endPos);
-	assertEquals("Doc (2)", 0, kr.getMatch(2).internalDocID);
-	assertEquals("StartPos (3)", 1, kr.getMatch(3).startPos);
-	assertEquals("EndPos (3)", 9, kr.getMatch(3).endPos);
-	assertEquals("Doc (3)", 0, kr.getMatch(3).internalDocID);
-	assertEquals("StartPos (4)", 1, kr.getMatch(4).startPos);
-	assertEquals("EndPos (4)", 9, kr.getMatch(4).endPos);
-	assertEquals("Doc (4)", 0, kr.getMatch(4).internalDocID);
-	assertEquals("StartPos (5)", 2, kr.getMatch(5).startPos);
-	assertEquals("EndPos (5)", 6, kr.getMatch(5).endPos);
-	assertEquals("Doc (5)", 0, kr.getMatch(5).internalDocID);
+        assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
+        assertEquals("EndPos (0)", 12, kr.getMatch(0).endPos);
+        assertEquals("Doc (0)", 0, kr.getMatch(0).internalDocID);
+        assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
+        assertEquals("EndPos (1)", 12, kr.getMatch(1).endPos);
+        assertEquals("Doc (1)", 0, kr.getMatch(1).internalDocID);
+        assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
+        assertEquals("EndPos (2)", 12, kr.getMatch(2).endPos);
+        assertEquals("Doc (2)", 0, kr.getMatch(2).internalDocID);
+        assertEquals("StartPos (3)", 1, kr.getMatch(3).startPos);
+        assertEquals("EndPos (3)", 9, kr.getMatch(3).endPos);
+        assertEquals("Doc (3)", 0, kr.getMatch(3).internalDocID);
+        assertEquals("StartPos (4)", 1, kr.getMatch(4).startPos);
+        assertEquals("EndPos (4)", 9, kr.getMatch(4).endPos);
+        assertEquals("Doc (4)", 0, kr.getMatch(4).internalDocID);
+        assertEquals("StartPos (5)", 2, kr.getMatch(5).startPos);
+        assertEquals("EndPos (5)", 6, kr.getMatch(5).endPos);
+        assertEquals("Doc (5)", 0, kr.getMatch(5).internalDocID);
 
-	assertEquals("StartPos (6)", 0, kr.getMatch(6).startPos);
-	assertEquals("EndPos (6)", 12, kr.getMatch(6).endPos);
-	assertEquals("Doc (6)", 1, kr.getMatch(6).internalDocID);
-	assertEquals("StartPos (7)", 0, kr.getMatch(7).startPos);
-	assertEquals("EndPos (7)", 12, kr.getMatch(7).endPos);
-	assertEquals("Doc (7)", 1, kr.getMatch(7).internalDocID);
-	assertEquals("StartPos (8)", 0, kr.getMatch(8).startPos);
-	assertEquals("EndPos (8)", 12, kr.getMatch(8).endPos);
-	assertEquals("Doc (8)", 1, kr.getMatch(8).internalDocID);
-	assertEquals("StartPos (9)", 1, kr.getMatch(9).startPos);
-	assertEquals("EndPos (9)", 9, kr.getMatch(9).endPos);
-	assertEquals("Doc (9)", 1, kr.getMatch(9).internalDocID);
-	assertEquals("StartPos (10)", 1, kr.getMatch(10).startPos);
-	assertEquals("EndPos (10)", 9, kr.getMatch(10).endPos);
-	assertEquals("Doc (10)", 1, kr.getMatch(10).internalDocID);
-	assertEquals("StartPos (11)", 2, kr.getMatch(11).startPos);
-	assertEquals("EndPos (11)", 6, kr.getMatch(11).endPos);
-	assertEquals("Doc (11)", 1, kr.getMatch(11).internalDocID);
+        assertEquals("StartPos (6)", 0, kr.getMatch(6).startPos);
+        assertEquals("EndPos (6)", 12, kr.getMatch(6).endPos);
+        assertEquals("Doc (6)", 1, kr.getMatch(6).internalDocID);
+        assertEquals("StartPos (7)", 0, kr.getMatch(7).startPos);
+        assertEquals("EndPos (7)", 12, kr.getMatch(7).endPos);
+        assertEquals("Doc (7)", 1, kr.getMatch(7).internalDocID);
+        assertEquals("StartPos (8)", 0, kr.getMatch(8).startPos);
+        assertEquals("EndPos (8)", 12, kr.getMatch(8).endPos);
+        assertEquals("Doc (8)", 1, kr.getMatch(8).internalDocID);
+        assertEquals("StartPos (9)", 1, kr.getMatch(9).startPos);
+        assertEquals("EndPos (9)", 9, kr.getMatch(9).endPos);
+        assertEquals("Doc (9)", 1, kr.getMatch(9).internalDocID);
+        assertEquals("StartPos (10)", 1, kr.getMatch(10).startPos);
+        assertEquals("EndPos (10)", 9, kr.getMatch(10).endPos);
+        assertEquals("Doc (10)", 1, kr.getMatch(10).internalDocID);
+        assertEquals("StartPos (11)", 2, kr.getMatch(11).startPos);
+        assertEquals("EndPos (11)", 6, kr.getMatch(11).endPos);
+        assertEquals("Doc (11)", 1, kr.getMatch(11).internalDocID);
 
-	assertEquals(2, ki.numberOf("documents"));
+        /*
+		for (KorapMatch km : kr.getMatches()){		
+			System.out.println(km.getStartPos() +","+km.getEndPos()+" "
+                               +km.getSnippetBrackets());
+		};	
+        */
+
+        assertEquals(2, ki.numberOf("documents"));
     };
 
 
     @Test
     public void indexExample1c () throws IOException {
-	// Cases 9, 12, 13
-	KorapIndex ki = new KorapIndex();
+        // Cases 9, 12, 13
+        KorapIndex ki = new KorapIndex();
 
-	// <a>x<a>y<a>zhij</a>hij</a>hij</a>
-	FieldDocument fd = new FieldDocument();
-	fd.addTV("base",
-		 "x   y   z   h   i   j   h   i   j   h   i   j   ",
-		 "[(0-3)s:x|<>:a#0-36$<i>12]" + // 1
-		 "[(3-6)s:y|<>:a#3-27$<i>9]" +  // 2
-		 "[(6-9)s:z|<>:a#6-18$<i>6]" +  // 3
-		 "[(9-12)s:h]" +   // 4
-		 "[(12-15)s:i]" +  // 5
-		 "[(15-18)s:j]" +  // 6
-		 "[(18-21)s:h]" +  // 7
-		 "[(21-24)s:i]" +  // 8
-		 "[(24-27)s:j]" +  // 9
-		 "[(27-30)s:h]" +  // 10
-		 "[(30-33)s:i]" +  // 11
-		 "[(33-36)s:j]");  // 12
-	ki.addDoc(fd);
+        // <a>x<a>y<a>zhij</a>hij</a>hij</a>
+        FieldDocument fd = new FieldDocument();
+        fd.addTV("base",
+                 "x   y   z   h   i   j   h   i   j   h   i   j   ",
+                 "[(0-3)s:x|<>:a#0-36$<i>12]" + // 1
+                 "[(3-6)s:y|<>:a#3-27$<i>9]" +  // 2
+                 "[(6-9)s:z|<>:a#6-18$<i>6]" +  // 3
+                 "[(9-12)s:h]" +   // 4
+                 "[(12-15)s:i]" +  // 5
+                 "[(15-18)s:j]" +  // 6
+                 "[(18-21)s:h]" +  // 7
+                 "[(21-24)s:i]" +  // 8
+                 "[(24-27)s:j]" +  // 9
+                 "[(27-30)s:h]" +  // 10
+                 "[(30-33)s:i]" +  // 11
+                 "[(33-36)s:j]");  // 12
+        ki.addDoc(fd);
+        
+        // <a>x<a>y<a>zabc</a>abc</a>abc</a>
+        fd = new FieldDocument();
+        fd.addTV("base",
+                 "x   y   z   a   b   c   a   b   c   a   b   c   ",
+                 "[(0-3)s:x|<>:a#0-36$<i>12]" + // 1
+                 "[(3-6)s:y|<>:a#3-27$<i>9]" +  // 2
+                 "[(6-9)s:z|<>:a#6-18$<i>6]" +  // 3
+                 "[(9-12)s:a]" +   // 4
+                 "[(12-15)s:b]" +  // 5
+                 "[(15-18)s:c]" +  // 6
+                 "[(18-21)s:a]" +  // 7
+                 "[(21-24)s:b]" +  // 8
+                 "[(24-27)s:c]" +  // 9
+                 "[(27-30)s:a]" +  // 10
+                 "[(30-33)s:b]" +  // 11
+                 "[(33-36)s:c]");  // 12
+        ki.addDoc(fd);
+        
+        // Save documents
+        ki.commit();
 
-	// <a>x<a>y<a>zabc</a>abc</a>abc</a>
-	fd = new FieldDocument();
-	fd.addTV("base",
-		 "x   y   z   a   b   c   a   b   c   a   b   c   ",
-		 "[(0-3)s:x|<>:a#0-36$<i>12]" + // 1
-		 "[(3-6)s:y|<>:a#3-27$<i>9]" +  // 2
-		 "[(6-9)s:z|<>:a#6-18$<i>6]" +  // 3
-		 "[(9-12)s:a]" +   // 4
-		 "[(12-15)s:b]" +  // 5
-		 "[(15-18)s:c]" +  // 6
-		 "[(18-21)s:a]" +  // 7
-		 "[(21-24)s:b]" +  // 8
-		 "[(24-27)s:c]" +  // 9
-		 "[(27-30)s:a]" +  // 10
-		 "[(30-33)s:b]" +  // 11
-		 "[(33-36)s:c]");  // 12
-	ki.addDoc(fd);
+        SpanQuery sq;
+        KorapResult kr;
 
-
-	// Save documents
-	ki.commit();
-
-	SpanQuery sq;
-	KorapResult kr;
-
-	sq = new SpanWithinQuery(
-	    new SpanElementQuery("base", "a"),
+        sq = new SpanWithinQuery(
+            new SpanElementQuery("base", "a"),
             new SpanTermQuery(new Term("base", "s:h"))
         );
 
-	kr = ki.search(sq, (short) 15);
+        kr = ki.search(sq, (short) 15);
 	
-	assertEquals("totalResults", kr.getTotalResults(), 6);
+        assertEquals("totalResults", kr.getTotalResults(), 6);
 
-	assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
-	assertEquals("EndPos (0)", 12, kr.getMatch(0).endPos);
-	assertEquals("Doc (0)", 0, kr.getMatch(0).internalDocID);
-	assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
-	assertEquals("EndPos (1)", 12, kr.getMatch(1).endPos);
-	assertEquals("Doc (1)", 0, kr.getMatch(1).internalDocID);
-	assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
-	assertEquals("EndPos (2)", 12, kr.getMatch(2).endPos);
-	assertEquals("Doc (2)", 0, kr.getMatch(2).internalDocID);
-	assertEquals("StartPos (3)", 1, kr.getMatch(3).startPos);
-	assertEquals("EndPos (3)", 9, kr.getMatch(3).endPos);
-	assertEquals("Doc (3)", 0, kr.getMatch(3).internalDocID);
-	assertEquals("StartPos (4)", 1, kr.getMatch(4).startPos);
-	assertEquals("EndPos (4)", 9, kr.getMatch(4).endPos);
-	assertEquals("Doc (4)", 0, kr.getMatch(4).internalDocID);
-	assertEquals("StartPos (5)", 2, kr.getMatch(5).startPos);
-	assertEquals("EndPos (5)", 6, kr.getMatch(5).endPos);
-	assertEquals("Doc (5)", 0, kr.getMatch(5).internalDocID);
+        assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
+        assertEquals("EndPos (0)", 12, kr.getMatch(0).endPos);
+        assertEquals("Doc (0)", 0, kr.getMatch(0).internalDocID);
+        assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
+        assertEquals("EndPos (1)", 12, kr.getMatch(1).endPos);
+        assertEquals("Doc (1)", 0, kr.getMatch(1).internalDocID);
+        assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
+        assertEquals("EndPos (2)", 12, kr.getMatch(2).endPos);
+        assertEquals("Doc (2)", 0, kr.getMatch(2).internalDocID);
+        assertEquals("StartPos (3)", 1, kr.getMatch(3).startPos);
+        assertEquals("EndPos (3)", 9, kr.getMatch(3).endPos);
+        assertEquals("Doc (3)", 0, kr.getMatch(3).internalDocID);
+        assertEquals("StartPos (4)", 1, kr.getMatch(4).startPos);
+        assertEquals("EndPos (4)", 9, kr.getMatch(4).endPos);
+        assertEquals("Doc (4)", 0, kr.getMatch(4).internalDocID);
+        assertEquals("StartPos (5)", 2, kr.getMatch(5).startPos);
+        assertEquals("EndPos (5)", 6, kr.getMatch(5).endPos);
+        assertEquals("Doc (5)", 0, kr.getMatch(5).internalDocID);
 
-	assertEquals(2, ki.numberOf("documents"));
+        assertEquals(2, ki.numberOf("documents"));
     };
 
 
     @Test
     public void indexExample1d () throws IOException {
-	// Cases 9, 12, 13
-	KorapIndex ki = new KorapIndex();
+        // Cases 9, 12, 13
+        KorapIndex ki = new KorapIndex();
 
-	// <a>x<a>y<a>zhij</a>hij</a>hij</a>
-	FieldDocument fd = new FieldDocument();
-	fd.addTV("base",
-		 "x   y   z   h   i   j   h   i   j   h   i   j   ",
-		 "[(0-3)s:x|<>:a#0-36$<i>12]" + // 1
-		 "[(3-6)s:y|<>:a#3-27$<i>9]" +  // 2
-		 "[(6-9)s:z|<>:a#6-18$<i>6]" +  // 3
-		 "[(9-12)s:h]" +   // 4
-		 "[(12-15)s:i]" +  // 5
-		 "[(15-18)s:j]" +  // 6
-		 "[(18-21)s:h]" +  // 7
-		 "[(21-24)s:i]" +  // 8
-		 "[(24-27)s:j]" +  // 9
-		 "[(27-30)s:h]" +  // 10
-		 "[(30-33)s:i]" +  // 11
-		 "[(33-36)s:j]");  // 12
-	ki.addDoc(fd);
+        // <a>x<a>y<a>zhij</a>hij</a>hij</a>
+        FieldDocument fd = new FieldDocument();
+        fd.addTV("base",
+                 "x   y   z   h   i   j   h   i   j   h   i   j   ",
+                 "[(0-3)s:x|<>:a#0-36$<i>12]" + // 1
+                 "[(3-6)s:y|<>:a#3-27$<i>9]" +  // 2
+                 "[(6-9)s:z|<>:a#6-18$<i>6]" +  // 3
+                 "[(9-12)s:h]" +   // 4
+                 "[(12-15)s:i]" +  // 5
+                 "[(15-18)s:j]" +  // 6
+                 "[(18-21)s:h]" +  // 7
+                 "[(21-24)s:i]" +  // 8
+                 "[(24-27)s:j]" +  // 9
+                 "[(27-30)s:h]" +  // 10
+                 "[(30-33)s:i]" +  // 11
+                 "[(33-36)s:j]");  // 12
+        ki.addDoc(fd);
 
-	fd = new FieldDocument();
-	fd.addTV("base",
-		 "x   y   z   h   ",
-		 "[(0-3)s:x]" +  // 1
-		 "[(3-6)s:y]" +  // 2
-		 "[(6-9)s:z]" +  // 3
-		 "[(9-12)s:h]"); // 4
-	ki.addDoc(fd);
+        fd = new FieldDocument();
+        fd.addTV("base",
+                 "x   y   z   h   ",
+                 "[(0-3)s:x]" +  // 1
+                 "[(3-6)s:y]" +  // 2
+                 "[(6-9)s:z]" +  // 3
+                 "[(9-12)s:h]"); // 4
+        ki.addDoc(fd);
 
-	// <a>x<a>y<a>zabc</a>abc</a>abc</a>
-	fd = new FieldDocument();
-	fd.addTV("base",
-		 "x   y   z   a   b   c   a   b   c   a   b   c   ",
-		 "[(0-3)s:x|<>:a#0-36$<i>12]" + // 1
-		 "[(3-6)s:y|<>:a#3-27$<i>9]" +  // 2
-		 "[(6-9)s:z|<>:a#6-18$<i>6]" +  // 3
-		 "[(9-12)s:a]" +   // 4
-		 "[(12-15)s:b]" +  // 5
-		 "[(15-18)s:c]" +  // 6
-		 "[(18-21)s:a]" +  // 7
-		 "[(21-24)s:b]" +  // 8
-		 "[(24-27)s:c]" +  // 9
-		 "[(27-30)s:a]" +  // 10
-		 "[(30-33)s:b]" +  // 11
-		 "[(33-36)s:c]");  // 12
-	ki.addDoc(fd);
+        // <a>x<a>y<a>zabc</a>abc</a>abc</a>
+        fd = new FieldDocument();
+        fd.addTV("base",
+                 "x   y   z   a   b   c   a   b   c   a   b   c   ",
+                 "[(0-3)s:x|<>:a#0-36$<i>12]" + // 1
+                 "[(3-6)s:y|<>:a#3-27$<i>9]" +  // 2
+                 "[(6-9)s:z|<>:a#6-18$<i>6]" +  // 3
+                 "[(9-12)s:a]" +   // 4
+                 "[(12-15)s:b]" +  // 5
+                 "[(15-18)s:c]" +  // 6
+                 "[(18-21)s:a]" +  // 7
+                 "[(21-24)s:b]" +  // 8
+                 "[(24-27)s:c]" +  // 9
+                 "[(27-30)s:a]" +  // 10
+                 "[(30-33)s:b]" +  // 11
+                 "[(33-36)s:c]");  // 12
+        ki.addDoc(fd);
 
-	// Save documents
-	ki.commit();
+        // Save documents
+        ki.commit();
 
-	SpanQuery sq;
-	KorapResult kr;
+        SpanQuery sq;
+        KorapResult kr;
 
-	sq = new SpanElementQuery("base", "a");
-	kr = ki.search(sq, (short) 15);
+        sq = new SpanElementQuery("base", "a");
+        kr = ki.search(sq, (short) 15);
 
-	sq = new SpanWithinQuery(
-	    new SpanElementQuery("base", "a"),
+        sq = new SpanWithinQuery(
+            new SpanElementQuery("base", "a"),
             new SpanTermQuery(new Term("base", "s:h"))
         );
 
-	kr = ki.search(sq, (short) 15);
+        kr = ki.search(sq, (short) 15);
 	
-	assertEquals("totalResults", kr.getTotalResults(), 6);
+        assertEquals("totalResults", kr.getTotalResults(), 6);
 
-	assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
-	assertEquals("EndPos (0)", 12, kr.getMatch(0).endPos);
-	assertEquals("Doc (0)", 0, kr.getMatch(0).internalDocID);
-	assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
-	assertEquals("EndPos (1)", 12, kr.getMatch(1).endPos);
-	assertEquals("Doc (1)", 0, kr.getMatch(1).internalDocID);
-	assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
-	assertEquals("EndPos (2)", 12, kr.getMatch(2).endPos);
-	assertEquals("Doc (2)", 0, kr.getMatch(2).internalDocID);
-	assertEquals("StartPos (3)", 1, kr.getMatch(3).startPos);
-	assertEquals("EndPos (3)", 9, kr.getMatch(3).endPos);
-	assertEquals("Doc (3)", 0, kr.getMatch(3).internalDocID);
-	assertEquals("StartPos (4)", 1, kr.getMatch(4).startPos);
-	assertEquals("EndPos (4)", 9, kr.getMatch(4).endPos);
-	assertEquals("Doc (4)", 0, kr.getMatch(4).internalDocID);
-	assertEquals("StartPos (5)", 2, kr.getMatch(5).startPos);
-	assertEquals("EndPos (5)", 6, kr.getMatch(5).endPos);
-	assertEquals("Doc (5)", 0, kr.getMatch(5).internalDocID);
-
-	assertEquals(3, ki.numberOf("documents"));
+        assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
+        assertEquals("EndPos (0)", 12, kr.getMatch(0).endPos);
+        assertEquals("Doc (0)", 0, kr.getMatch(0).internalDocID);
+        assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
+        assertEquals("EndPos (1)", 12, kr.getMatch(1).endPos);
+        assertEquals("Doc (1)", 0, kr.getMatch(1).internalDocID);
+        assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
+        assertEquals("EndPos (2)", 12, kr.getMatch(2).endPos);
+        assertEquals("Doc (2)", 0, kr.getMatch(2).internalDocID);
+        assertEquals("StartPos (3)", 1, kr.getMatch(3).startPos);
+        assertEquals("EndPos (3)", 9, kr.getMatch(3).endPos);
+        assertEquals("Doc (3)", 0, kr.getMatch(3).internalDocID);
+        assertEquals("StartPos (4)", 1, kr.getMatch(4).startPos);
+        assertEquals("EndPos (4)", 9, kr.getMatch(4).endPos);
+        assertEquals("Doc (4)", 0, kr.getMatch(4).internalDocID);
+        assertEquals("StartPos (5)", 2, kr.getMatch(5).startPos);
+        assertEquals("EndPos (5)", 6, kr.getMatch(5).endPos);
+        assertEquals("Doc (5)", 0, kr.getMatch(5).internalDocID);
+        
+        assertEquals(3, ki.numberOf("documents"));
     };
-
-
-
-
-
+    
     @Test
     public void indexExample2a () throws IOException {
-	KorapIndex ki = new KorapIndex();
+        KorapIndex ki = new KorapIndex();
 
-	// <a><a><a>h</a>hij</a>hij</a>
-	FieldDocument fd = new FieldDocument();
-	fd.addTV("base",
-		 "h   i   j   h   i   j   h   i   j   ",
-		 "[(0-3)s:h|<>:a#0-27$<i>7|<>:a#0-18$<i>4|<>:a#0-36$<i>10]" + // 1
-		 "[(3-6)s:h]" +    // 2
-		 "[(12-15)s:i]" +  // 3
-		 "[(15-18)s:j]" +  // 4
-		 "[(18-21)s:h]" +  // 5
-		 "[(21-24)s:i]" +  // 6
-		 "[(24-27)s:j]" +  // 7
-		 "[(27-30)s:h]" +  // 8
-		 "[(30-33)s:i]" +  // 9
-		 "[(33-36)s:j]");  // 10
-	ki.addDoc(fd);
+        // <a><a><a>h</a>hij</a>hij</a>
+        FieldDocument fd = new FieldDocument();
+        fd.addTV("base",
+                 "h   i   j   h   i   j   h   i   j   ",
+                 "[(0-3)s:h|<>:a#0-27$<i>7|<>:a#0-18$<i>4|<>:a#0-36$<i>10]" + // 1
+                 "[(3-6)s:h]" +    // 2
+                 "[(12-15)s:i]" +  // 3
+                 "[(15-18)s:j]" +  // 4
+                 "[(18-21)s:h]" +  // 5
+                 "[(21-24)s:i]" +  // 6
+                 "[(24-27)s:j]" +  // 7
+                 "[(27-30)s:h]" +  // 8
+                 "[(30-33)s:i]" +  // 9
+                 "[(33-36)s:j]");  // 10
+        ki.addDoc(fd);
 
-	// Save documents
-	ki.commit();
+        // Save documents
+        ki.commit();
 
-	assertEquals(1, ki.numberOf("documents"));
+        assertEquals(1, ki.numberOf("documents"));
 
-	SpanQuery sq;
-	KorapResult kr;
+        SpanQuery sq;
+        KorapResult kr;
 
-	sq = new SpanElementQuery("base", "a");
-	kr = ki.search(sq, (short) 10);
+        sq = new SpanElementQuery("base", "a");
+        kr = ki.search(sq, (short) 10);
 
-	assertEquals("totalResults", kr.getTotalResults(), 3);
-	assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
-	assertEquals("EndPos (0)", 4, kr.getMatch(0).endPos);
-	assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
-	assertEquals("EndPos (1)", 7, kr.getMatch(1).endPos);
-	assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
-	assertEquals("EndPos (2)", 10, kr.getMatch(2).endPos);
+        assertEquals("totalResults", kr.getTotalResults(), 3);
+        assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
+        assertEquals("EndPos (0)", 4, kr.getMatch(0).endPos);
+        assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
+        assertEquals("EndPos (1)", 7, kr.getMatch(1).endPos);
+        assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
+        assertEquals("EndPos (2)", 10, kr.getMatch(2).endPos);
 	    
-	sq = new SpanWithinQuery(
-	    new SpanElementQuery("base", "a"),
+        sq = new SpanWithinQuery(
+            new SpanElementQuery("base", "a"),
             new SpanTermQuery(new Term("base", "s:h"))
         );
 
-	kr = ki.search(sq, (short) 10);
+        kr = ki.search(sq, (short) 10);
 
-	assertEquals("totalResults", kr.getTotalResults(), 9);
-	assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
-	assertEquals("EndPos (0)", 4, kr.getMatch(0).endPos);
-	assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
-	assertEquals("EndPos (1)", 4, kr.getMatch(1).endPos);
-	assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
-	assertEquals("EndPos (2)", 7, kr.getMatch(2).endPos);
-	assertEquals("StartPos (3)", 0, kr.getMatch(3).startPos);
-	assertEquals("EndPos (3)", 7, kr.getMatch(3).endPos);
-	assertEquals("StartPos (4)", 0, kr.getMatch(4).startPos);
-	assertEquals("EndPos (4)", 7, kr.getMatch(4).endPos);
-	assertEquals("StartPos (5)", 0, kr.getMatch(5).startPos);
-	assertEquals("EndPos (5)", 10, kr.getMatch(5).endPos);
-	assertEquals("StartPos (6)", 0, kr.getMatch(6).startPos);
-	assertEquals("EndPos (6)", 10, kr.getMatch(6).endPos);
-	assertEquals("StartPos (7)", 0, kr.getMatch(7).startPos);
-	assertEquals("EndPos (7)", 10, kr.getMatch(7).endPos);
-	assertEquals("StartPos (8)", 0, kr.getMatch(8).startPos);
-	assertEquals("EndPos (8)", 10, kr.getMatch(8).endPos);
+        assertEquals("totalResults", kr.getTotalResults(), 9);
+        assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
+        assertEquals("EndPos (0)", 4, kr.getMatch(0).endPos);
+        assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
+        assertEquals("EndPos (1)", 4, kr.getMatch(1).endPos);
+        assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
+        assertEquals("EndPos (2)", 7, kr.getMatch(2).endPos);
+        assertEquals("StartPos (3)", 0, kr.getMatch(3).startPos);
+        assertEquals("EndPos (3)", 7, kr.getMatch(3).endPos);
+        assertEquals("StartPos (4)", 0, kr.getMatch(4).startPos);
+        assertEquals("EndPos (4)", 7, kr.getMatch(4).endPos);
+        assertEquals("StartPos (5)", 0, kr.getMatch(5).startPos);
+        assertEquals("EndPos (5)", 10, kr.getMatch(5).endPos);
+        assertEquals("StartPos (6)", 0, kr.getMatch(6).startPos);
+        assertEquals("EndPos (6)", 10, kr.getMatch(6).endPos);
+        assertEquals("StartPos (7)", 0, kr.getMatch(7).startPos);
+        assertEquals("EndPos (7)", 10, kr.getMatch(7).endPos);
+        assertEquals("StartPos (8)", 0, kr.getMatch(8).startPos);
+        assertEquals("EndPos (8)", 10, kr.getMatch(8).endPos);
     };
 
     @Test
     public void indexExample2b () throws IOException {
-	KorapIndex ki = new KorapIndex();
+        KorapIndex ki = new KorapIndex();
 
-	// 6,9,12
-	// <a><a><a>h</a>hij</a>hij</a>h
-	FieldDocument fd = new FieldDocument();
-	fd.addTV("base",
-		 "h   i   j   h   i   j   h   i   j   h   ",
-		 "[(0-3)s:h|<>:a#0-27$<i>7|<>:a#0-18$<i>4|<>:a#0-36$<i>10]" + // 1
-		 "[(3-6)s:h]" +    // 2
-		 "[(12-15)s:i]" +  // 3
-		 "[(15-18)s:j]" +  // 4
-		 "[(18-21)s:h]" +  // 5
-		 "[(21-24)s:i]" +  // 6
-		 "[(24-27)s:j]" +  // 7
-		 "[(27-30)s:h]" +  // 8
-		 "[(30-33)s:i]" +  // 9
-		 "[(33-36)s:j]" +  // 10
-		 "[(37-40)s:h]");
-	ki.addDoc(fd);
+        // 6,9,12
+        // <a><a><a>h</a>hij</a>hij</a>h
+        FieldDocument fd = new FieldDocument();
+        fd.addTV("base",
+                 "h   i   j   h   i   j   h   i   j   h   ",
+                 "[(0-3)s:h|<>:a#0-27$<i>7|<>:a#0-18$<i>4|<>:a#0-36$<i>10]" + // 1
+                 "[(3-6)s:h]" +    // 2
+                 "[(12-15)s:i]" +  // 3
+                 "[(15-18)s:j]" +  // 4
+                 "[(18-21)s:h]" +  // 5
+                 "[(21-24)s:i]" +  // 6
+                 "[(24-27)s:j]" +  // 7
+                 "[(27-30)s:h]" +  // 8
+                 "[(30-33)s:i]" +  // 9
+                 "[(33-36)s:j]" +  // 10
+                 "[(37-40)s:h]");
+        ki.addDoc(fd);
 
-	// Save documents
-	ki.commit();
+        // Save documents
+        ki.commit();
 
-	assertEquals(1, ki.numberOf("documents"));
+        assertEquals(1, ki.numberOf("documents"));
 
-	SpanQuery sq = new SpanElementQuery("base", "a");
+        SpanQuery sq = new SpanElementQuery("base", "a");
+        KorapResult kr = ki.search(sq, (short) 10);
 
-	KorapResult kr = ki.search(sq, (short) 10);
-
-	assertEquals("totalResults", kr.getTotalResults(), 3);
-	assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
-	assertEquals("EndPos (0)", 4, kr.getMatch(0).endPos);
-	assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
-	assertEquals("EndPos (1)", 7, kr.getMatch(1).endPos);
-	assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
-	assertEquals("EndPos (2)", 10, kr.getMatch(2).endPos);
-
-	sq = new SpanWithinQuery(
-	    new SpanElementQuery("base", "a"),
+        assertEquals("totalResults", kr.getTotalResults(), 3);
+        assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
+        assertEquals("EndPos (0)", 4, kr.getMatch(0).endPos);
+        assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
+        assertEquals("EndPos (1)", 7, kr.getMatch(1).endPos);
+        assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
+        assertEquals("EndPos (2)", 10, kr.getMatch(2).endPos);
+        
+        sq = new SpanWithinQuery(
+            new SpanElementQuery("base", "a"),
             new SpanTermQuery(new Term("base", "s:h"))
         );
 
-	kr = ki.search(sq, (short) 10);
+        kr = ki.search(sq, (short) 10);
 
-	assertEquals("totalResults", kr.getTotalResults(), 9);
-	assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
-	assertEquals("EndPos (0)", 4, kr.getMatch(0).endPos);
-	assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
-	assertEquals("EndPos (1)", 4, kr.getMatch(1).endPos);
-	assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
-	assertEquals("EndPos (2)", 7, kr.getMatch(2).endPos);
-	assertEquals("StartPos (3)", 0, kr.getMatch(3).startPos);
-	assertEquals("EndPos (3)", 7, kr.getMatch(3).endPos);
-	assertEquals("StartPos (4)", 0, kr.getMatch(4).startPos);
-	assertEquals("EndPos (4)", 7, kr.getMatch(4).endPos);
-	assertEquals("StartPos (5)", 0, kr.getMatch(5).startPos);
-	assertEquals("EndPos (5)", 10, kr.getMatch(5).endPos);
-	assertEquals("StartPos (6)", 0, kr.getMatch(6).startPos);
-	assertEquals("EndPos (6)", 10, kr.getMatch(6).endPos);
-	assertEquals("StartPos (7)", 0, kr.getMatch(7).startPos);
-	assertEquals("EndPos (7)", 10, kr.getMatch(7).endPos);
-	assertEquals("StartPos (8)", 0, kr.getMatch(8).startPos);
-	assertEquals("EndPos (8)", 10, kr.getMatch(8).endPos);
+        assertEquals("totalResults", kr.getTotalResults(), 9);
+        assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
+        assertEquals("EndPos (0)", 4, kr.getMatch(0).endPos);
+        assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
+        assertEquals("EndPos (1)", 4, kr.getMatch(1).endPos);
+        assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
+        assertEquals("EndPos (2)", 7, kr.getMatch(2).endPos);
+        assertEquals("StartPos (3)", 0, kr.getMatch(3).startPos);
+        assertEquals("EndPos (3)", 7, kr.getMatch(3).endPos);
+        assertEquals("StartPos (4)", 0, kr.getMatch(4).startPos);
+        assertEquals("EndPos (4)", 7, kr.getMatch(4).endPos);
+        assertEquals("StartPos (5)", 0, kr.getMatch(5).startPos);
+        assertEquals("EndPos (5)", 10, kr.getMatch(5).endPos);
+        assertEquals("StartPos (6)", 0, kr.getMatch(6).startPos);
+        assertEquals("EndPos (6)", 10, kr.getMatch(6).endPos);
+        assertEquals("StartPos (7)", 0, kr.getMatch(7).startPos);
+        assertEquals("EndPos (7)", 10, kr.getMatch(7).endPos);
+        assertEquals("StartPos (8)", 0, kr.getMatch(8).startPos);
+        assertEquals("EndPos (8)", 10, kr.getMatch(8).endPos);
     };
 
 
     @Test
     public void indexExample2c () throws IOException {
-	KorapIndex ki = new KorapIndex();
+        KorapIndex ki = new KorapIndex();
 
-	// 2, 6, 9, 12
-	// <a><a><a>h</a>hij</a>hij</a>h<a>i</i>
-	FieldDocument fd = new FieldDocument();
-	fd.addTV("base",
-		 "h   i   j   h   i   j   h   i   j   h   i   ",
-		 "[(0-3)s:h|<>:a#0-27$<i>7|<>:a#0-18$<i>4|<>:a#0-36$<i>10]" + // 1
-		 "[(3-6)s:h]" +    // 2
-		 "[(12-15)s:i]" +  // 3
-		 "[(15-18)s:j]" +  // 4
-		 "[(18-21)s:h]" +  // 5
-		 "[(21-24)s:i]" +  // 6
-		 "[(24-27)s:j]" +  // 7
-		 "[(27-30)s:h]" +  // 8
-		 "[(30-33)s:i]" +  // 9
-		 "[(33-36)s:j]" +  // 10
-		 "[(37-40)s:h]" +  // 11
-		 "[(40-43)s:i|<>:a#40-43$<i>12]"); // 12
-	ki.addDoc(fd);
+        // 2, 6, 9, 12
+        // <a><a><a>h</a>hij</a>hij</a>h<a>i</i>
+        FieldDocument fd = new FieldDocument();
+        fd.addTV("base",
+                 "h   i   j   h   i   j   h   i   j   h   i   ",
+                 "[(0-3)s:h|<>:a#0-27$<i>7|<>:a#0-18$<i>4|<>:a#0-36$<i>10]" + // 1
+                 "[(3-6)s:h]" +    // 2
+                 "[(12-15)s:i]" +  // 3
+                 "[(15-18)s:j]" +  // 4
+                 "[(18-21)s:h]" +  // 5
+                 "[(21-24)s:i]" +  // 6
+                 "[(24-27)s:j]" +  // 7
+                 "[(27-30)s:h]" +  // 8
+                 "[(30-33)s:i]" +  // 9
+                 "[(33-36)s:j]" +  // 10
+                 "[(37-40)s:h]" +  // 11
+                 "[(40-43)s:i|<>:a#40-43$<i>12]"); // 12
+        ki.addDoc(fd);
+        
+        // Save documents
+        ki.commit();
 
-	// Save documents
-	ki.commit();
+        assertEquals(1, ki.numberOf("documents"));
 
-	assertEquals(1, ki.numberOf("documents"));
+        SpanQuery sq = new SpanElementQuery("base", "a");
 
-	SpanQuery sq = new SpanElementQuery("base", "a");
+        KorapResult kr = ki.search(sq, (short) 10);
+    
+        assertEquals("totalResults", kr.getTotalResults(), 4);
+        assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
+        assertEquals("EndPos (0)", 4, kr.getMatch(0).endPos);
+        assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
+        assertEquals("EndPos (1)", 7, kr.getMatch(1).endPos);
+        assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
+        assertEquals("EndPos (2)", 10, kr.getMatch(2).endPos);
+        assertEquals("StartPos (3)", 11, kr.getMatch(3).startPos);
+        assertEquals("EndPos (3)", 12, kr.getMatch(3).endPos);
 
-	KorapResult kr = ki.search(sq, (short) 10);
-
-	assertEquals("totalResults", kr.getTotalResults(), 4);
-	assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
-	assertEquals("EndPos (0)", 4, kr.getMatch(0).endPos);
-	assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
-	assertEquals("EndPos (1)", 7, kr.getMatch(1).endPos);
-	assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
-	assertEquals("EndPos (2)", 10, kr.getMatch(2).endPos);
-	assertEquals("StartPos (3)", 11, kr.getMatch(3).startPos);
-	assertEquals("EndPos (3)", 12, kr.getMatch(3).endPos);
-
-	sq = new SpanWithinQuery(
-	    new SpanElementQuery("base", "a"),
+        sq = new SpanWithinQuery(
+	        new SpanElementQuery("base", "a"),
             new SpanTermQuery(new Term("base", "s:h"))
         );
 
-	kr = ki.search(sq, (short) 10);
+        kr = ki.search(sq, (short) 10);
 
-	assertEquals("totalResults", kr.getTotalResults(), 9);
-	assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
-	assertEquals("EndPos (0)", 4, kr.getMatch(0).endPos);
-	assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
-	assertEquals("EndPos (1)", 4, kr.getMatch(1).endPos);
-	assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
-	assertEquals("EndPos (2)", 7, kr.getMatch(2).endPos);
-	assertEquals("StartPos (3)", 0, kr.getMatch(3).startPos);
-	assertEquals("EndPos (3)", 7, kr.getMatch(3).endPos);
-	assertEquals("StartPos (4)", 0, kr.getMatch(4).startPos);
-	assertEquals("EndPos (4)", 7, kr.getMatch(4).endPos);
-	assertEquals("StartPos (5)", 0, kr.getMatch(5).startPos);
-	assertEquals("EndPos (5)", 10, kr.getMatch(5).endPos);
-	assertEquals("StartPos (6)", 0, kr.getMatch(6).startPos);
-	assertEquals("EndPos (6)", 10, kr.getMatch(6).endPos);
-	assertEquals("StartPos (7)", 0, kr.getMatch(7).startPos);
-	assertEquals("EndPos (7)", 10, kr.getMatch(7).endPos);
-	assertEquals("StartPos (8)", 0, kr.getMatch(8).startPos);
-	assertEquals("EndPos (8)", 10, kr.getMatch(8).endPos);
+        assertEquals("totalResults", kr.getTotalResults(), 9);
+        assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
+        assertEquals("EndPos (0)", 4, kr.getMatch(0).endPos);
+        assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
+        assertEquals("EndPos (1)", 4, kr.getMatch(1).endPos);
+        assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
+        assertEquals("EndPos (2)", 7, kr.getMatch(2).endPos);
+        assertEquals("StartPos (3)", 0, kr.getMatch(3).startPos);
+        assertEquals("EndPos (3)", 7, kr.getMatch(3).endPos);
+        assertEquals("StartPos (4)", 0, kr.getMatch(4).startPos);
+        assertEquals("EndPos (4)", 7, kr.getMatch(4).endPos);
+        assertEquals("StartPos (5)", 0, kr.getMatch(5).startPos);
+        assertEquals("EndPos (5)", 10, kr.getMatch(5).endPos);
+        assertEquals("StartPos (6)", 0, kr.getMatch(6).startPos);
+        assertEquals("EndPos (6)", 10, kr.getMatch(6).endPos);
+        assertEquals("StartPos (7)", 0, kr.getMatch(7).startPos);
+        assertEquals("EndPos (7)", 10, kr.getMatch(7).endPos);
+        assertEquals("StartPos (8)", 0, kr.getMatch(8).startPos);
+        assertEquals("EndPos (8)", 10, kr.getMatch(8).endPos);
     };
 
 
     @Test
     public void indexExample2d () throws IOException {
-	KorapIndex ki = new KorapIndex();
+        KorapIndex ki = new KorapIndex();
+        
+        // 2, 6, 9, 12, 7
+        // <a><a><a>h</a>hij</a>hij</a>h<a>h</h>
+        FieldDocument fd = new FieldDocument();
+        fd.addTV("base",
+                 "h   i   j   h   i   j   h   i   j   h   i   ",
+                 "[(0-3)s:h|<>:a#0-27$<i>7|<>:a#0-18$<i>4|<>:a#0-36$<i>10]" + // 1
+                 "[(3-6)s:h]" +    // 2
+                 "[(12-15)s:i]" +  // 3
+                 "[(15-18)s:j]" +  // 4
+                 "[(18-21)s:h]" +  // 5
+                 "[(21-24)s:i]" +  // 6
+                 "[(24-27)s:j]" +  // 7
+                 "[(27-30)s:h]" +  // 8
+                 "[(30-33)s:i]" +  // 9
+                 "[(33-36)s:j]" +  // 10
+                 "[(37-40)s:h]" +  // 11
+                 "[(40-43)s:h|<>:a#40-43$<i>12]"); // 12
+        ki.addDoc(fd);
 
-	// 2, 6, 9, 12, 7
-	// <a><a><a>h</a>hij</a>hij</a>h<a>h</h>
-	FieldDocument fd = new FieldDocument();
-	fd.addTV("base",
-		 "h   i   j   h   i   j   h   i   j   h   i   ",
-		 "[(0-3)s:h|<>:a#0-27$<i>7|<>:a#0-18$<i>4|<>:a#0-36$<i>10]" + // 1
-		 "[(3-6)s:h]" +    // 2
-		 "[(12-15)s:i]" +  // 3
-		 "[(15-18)s:j]" +  // 4
-		 "[(18-21)s:h]" +  // 5
-		 "[(21-24)s:i]" +  // 6
-		 "[(24-27)s:j]" +  // 7
-		 "[(27-30)s:h]" +  // 8
-		 "[(30-33)s:i]" +  // 9
-		 "[(33-36)s:j]" +  // 10
-		 "[(37-40)s:h]" +  // 11
-		 "[(40-43)s:h|<>:a#40-43$<i>12]"); // 12
-	ki.addDoc(fd);
+        // Save documents
+        ki.commit();
 
-	// Save documents
-	ki.commit();
+        assertEquals(1, ki.numberOf("documents"));
 
-	assertEquals(1, ki.numberOf("documents"));
+        SpanQuery sq = new SpanElementQuery("base", "a");
 
-	SpanQuery sq = new SpanElementQuery("base", "a");
+        KorapResult kr = ki.search(sq, (short) 10);
+    
+        assertEquals("totalResults", kr.getTotalResults(), 4);
+        assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
+        assertEquals("EndPos (0)", 4, kr.getMatch(0).endPos);
+        assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
+        assertEquals("EndPos (1)", 7, kr.getMatch(1).endPos);
+        assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
+        assertEquals("EndPos (2)", 10, kr.getMatch(2).endPos);
+        assertEquals("StartPos (3)", 11, kr.getMatch(3).startPos);
+        assertEquals("EndPos (3)", 12, kr.getMatch(3).endPos);
 
-	KorapResult kr = ki.search(sq, (short) 10);
-
-	assertEquals("totalResults", kr.getTotalResults(), 4);
-	assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
-	assertEquals("EndPos (0)", 4, kr.getMatch(0).endPos);
-	assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
-	assertEquals("EndPos (1)", 7, kr.getMatch(1).endPos);
-	assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
-	assertEquals("EndPos (2)", 10, kr.getMatch(2).endPos);
-	assertEquals("StartPos (3)", 11, kr.getMatch(3).startPos);
-	assertEquals("EndPos (3)", 12, kr.getMatch(3).endPos);
-
-	sq = new SpanWithinQuery(
-	    new SpanElementQuery("base", "a"),
+        sq = new SpanWithinQuery(
+            new SpanElementQuery("base", "a"),
             new SpanTermQuery(new Term("base", "s:h"))
         );
 
-	kr = ki.search(sq, (short) 15);
+        kr = ki.search(sq, (short) 15);
 
-	assertEquals("totalResults", kr.getTotalResults(), 10);
-	assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
-	assertEquals("EndPos (0)", 4, kr.getMatch(0).endPos);
-	assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
-	assertEquals("EndPos (1)", 4, kr.getMatch(1).endPos);
-	assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
-	assertEquals("EndPos (2)", 7, kr.getMatch(2).endPos);
-	assertEquals("StartPos (3)", 0, kr.getMatch(3).startPos);
-	assertEquals("EndPos (3)", 7, kr.getMatch(3).endPos);
-	assertEquals("StartPos (4)", 0, kr.getMatch(4).startPos);
-	assertEquals("EndPos (4)", 7, kr.getMatch(4).endPos);
-	assertEquals("StartPos (5)", 0, kr.getMatch(5).startPos);
-	assertEquals("EndPos (5)", 10, kr.getMatch(5).endPos);
-	assertEquals("StartPos (6)", 0, kr.getMatch(6).startPos);
-	assertEquals("EndPos (6)", 10, kr.getMatch(6).endPos);
-	assertEquals("StartPos (7)", 0, kr.getMatch(7).startPos);
-	assertEquals("EndPos (7)", 10, kr.getMatch(7).endPos);
-	assertEquals("StartPos (8)", 0, kr.getMatch(8).startPos);
-	assertEquals("EndPos (8)", 10, kr.getMatch(8).endPos);
-	assertEquals("StartPos (9)", 11, kr.getMatch(9).startPos);
-	assertEquals("EndPos (9)", 12, kr.getMatch(9).endPos);
+        assertEquals("totalResults", kr.getTotalResults(), 10);
+        assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
+        assertEquals("EndPos (0)", 4, kr.getMatch(0).endPos);
+        assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
+        assertEquals("EndPos (1)", 4, kr.getMatch(1).endPos);
+        assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
+        assertEquals("EndPos (2)", 7, kr.getMatch(2).endPos);
+        assertEquals("StartPos (3)", 0, kr.getMatch(3).startPos);
+        assertEquals("EndPos (3)", 7, kr.getMatch(3).endPos);
+        assertEquals("StartPos (4)", 0, kr.getMatch(4).startPos);
+        assertEquals("EndPos (4)", 7, kr.getMatch(4).endPos);
+        assertEquals("StartPos (5)", 0, kr.getMatch(5).startPos);
+        assertEquals("EndPos (5)", 10, kr.getMatch(5).endPos);
+        assertEquals("StartPos (6)", 0, kr.getMatch(6).startPos);
+        assertEquals("EndPos (6)", 10, kr.getMatch(6).endPos);
+        assertEquals("StartPos (7)", 0, kr.getMatch(7).startPos);
+        assertEquals("EndPos (7)", 10, kr.getMatch(7).endPos);
+        assertEquals("StartPos (8)", 0, kr.getMatch(8).startPos);
+        assertEquals("EndPos (8)", 10, kr.getMatch(8).endPos);
+        assertEquals("StartPos (9)", 11, kr.getMatch(9).startPos);
+        assertEquals("EndPos (9)", 12, kr.getMatch(9).endPos);
     };
 
 
     @Test
     public void indexExample3 () throws IOException {
-	KorapIndex ki = new KorapIndex();
+        KorapIndex ki = new KorapIndex();
 
-	// <a><a><a>u</a></a></a>
-	FieldDocument fd = new FieldDocument();
-	fd.addTV("base",
-		 "xyz",
-		 "[(0-3)s:xyz|<>:a#0-3$<i>0|<>:a#0-3$<i>0|<>:a#0-3$<i>0|<>:b#0-3$<i>0]");
-	ki.addDoc(fd);
+        // <a><a><a>u</a></a></a>
+        FieldDocument fd = new FieldDocument();
+        fd.addTV("base",
+                 "xyz",
+                 "[(0-3)s:xyz|<>:a#0-3$<i>0|<>:a#0-3$<i>0|<>:a#0-3$<i>0|<>:b#0-3$<i>0]");
+        ki.addDoc(fd);
+        
+        // <a><b>x<a>y<a>zcde</a>cde</a>cde</b></a>
+        fd = new FieldDocument();
+        fd.addTV("base",
+                 "x   y   z   c   d   e   c   d   e   c   d   e   ",
+                 "[(0-3)s:x|<>:a#0-36$<i>12|<>:b#0-36$<i>12]" +
+                 "[(3-6)s:y|<>:a#3-27$<i>9]" +
+                 "[(6-9)s:z|<>:a#6-18$<i>6]" +
+                 "[(9-12)s:c]" +
+                 "[(12-15)s:d]" +
+                 "[(15-18)s:e]" +
+                 "[(18-21)s:c]" +
+                 "[(21-24)s:d]" +
+                 "[(24-27)s:e]" +
+                 "[(27-30)s:c]" +
+                 "[(30-33)s:d]" +
+                 "[(33-36)s:e]");
+        ki.addDoc(fd);
 
-	// <a><b>x<a>y<a>zcde</a>cde</a>cde</b></a>
-	fd = new FieldDocument();
-	fd.addTV("base",
-		 "x   y   z   c   d   e   c   d   e   c   d   e   ",
-		 "[(0-3)s:x|<>:a#0-36$<i>12|<>:b#0-36$<i>12]" +
-		 "[(3-6)s:y|<>:a#3-27$<i>9]" +
-		 "[(6-9)s:z|<>:a#6-18$<i>6]" +
-		 "[(9-12)s:c]" +
-		 "[(12-15)s:d]" +
-		 "[(15-18)s:e]" +
-		 "[(18-21)s:c]" +
-		 "[(21-24)s:d]" +
-		 "[(24-27)s:e]" +
-		 "[(27-30)s:c]" +
-		 "[(30-33)s:d]" +
-		 "[(33-36)s:e]");
-	ki.addDoc(fd);
+        // xyz
+        fd = new FieldDocument();
+        fd.addTV("base",
+                 "x   y   z   ",
+                 "[(0-3)s:x]" +
+                 "[(3-6)s:y]" +
+                 "[(6-9)s:z]");
+        ki.addDoc(fd);
+        
+        // <a>x<a><b>y<a>zcde</a>cde</b></a>cde</a>
+        fd = new FieldDocument();
+        fd.addTV("base",
+                 "x   y   z   k   l   m   k   l   m   k   l   m   ",
+                 "[(0-3)s:x|<>:a#0-3$<i>12]" +
+                 "[(3-6)s:y|<>:a#3-6$<i>9|<>:b#3-6$<i>9]" +
+                 "[(6-9)s:z|<>:a#6-9$<i>6]" +
+                 "[(9-12)s:k]" +
+                 "[(12-15)s:l]" +
+                 "[(15-18)s:m]" +
+                 "[(18-21)s:k]" +
+                 "[(21-24)s:l]" +
+                 "[(24-27)s:m]" +
+                 "[(27-30)s:k]" +
+                 "[(30-33)s:l]" +
+                 "[(33-36)s:m]");
+        ki.addDoc(fd);
 
-	// xyz
-	fd = new FieldDocument();
-	fd.addTV("base",
-		 "x   y   z   ",
-		 "[(0-3)s:x]" +
-		 "[(3-6)s:y]" +
-		 "[(6-9)s:z]");
-	ki.addDoc(fd);
+        // <a><a><a>h</a>hhij</a>hij</a>hij</a>
+        fd = new FieldDocument();
+        fd.addTV("base",
+                 "h   i   j   h   i   j   h   i   j   ",
+                 "[(0-3)s:h|<>:a#0-27$<i>6|<>:a#0-18$<i>3|<>:a#0-36$<i>9]" +
+                 "[(3-6)s:h]" +
+                 "[(12-15)s:i]" +
+                 "[(15-18)s:j]" +
+                 "[(18-21)s:h]" +
+                 "[(21-24)s:i]" +
+                 "[(24-27)s:j]" +
+                 "[(27-30)s:h]" +
+                 "[(30-33)s:i]" +
+                 "[(33-36)s:j]");
+        ki.addDoc(fd);
 
-	// <a>x<a><b>y<a>zcde</a>cde</b></a>cde</a>
-	fd = new FieldDocument();
-	fd.addTV("base",
-		 "x   y   z   k   l   m   k   l   m   k   l   m   ",
-		 "[(0-3)s:x|<>:a#0-3$<i>12]" +
-		 "[(3-6)s:y|<>:a#3-6$<i>9|<>:b#3-6$<i>9]" +
-		 "[(6-9)s:z|<>:a#6-9$<i>6]" +
-		 "[(9-12)s:k]" +
-		 "[(12-15)s:l]" +
-		 "[(15-18)s:m]" +
-		 "[(18-21)s:k]" +
-		 "[(21-24)s:l]" +
-		 "[(24-27)s:m]" +
-		 "[(27-30)s:k]" +
-		 "[(30-33)s:l]" +
-		 "[(33-36)s:m]");
-	ki.addDoc(fd);
+        // xyz
+        fd = new FieldDocument();
+        fd.addTV("base",
+                 "a  b  c  ",
+                 "[(0-3)s:a]" +
+                 "[(3-6)s:b]" +
+                 "[(6-9)s:c]");
+        ki.addDoc(fd);
 
-	// <a><a><a>h</a>hhij</a>hij</a>hij</a>
-	fd = new FieldDocument();
-	fd.addTV("base",
-		 "h   i   j   h   i   j   h   i   j   ",
-		 "[(0-3)s:h|<>:a#0-27$<i>6|<>:a#0-18$<i>3|<>:a#0-36$<i>9]" +
-		 "[(3-6)s:h]" +
-		 "[(12-15)s:i]" +
-		 "[(15-18)s:j]" +
-		 "[(18-21)s:h]" +
-		 "[(21-24)s:i]" +
-		 "[(24-27)s:j]" +
-		 "[(27-30)s:h]" +
-		 "[(30-33)s:i]" +
-		 "[(33-36)s:j]");
-	ki.addDoc(fd);
+        // Save documents
+        ki.commit();
+    
+        assertEquals(6, ki.numberOf("documents"));
 
-	// xyz
-	fd = new FieldDocument();
-	fd.addTV("base",
-		 "a  b  c  ",
-		 "[(0-3)s:a]" +
-		 "[(3-6)s:b]" +
-		 "[(6-9)s:c]");
-	ki.addDoc(fd);
+        SpanQuery sq = new SpanElementQuery("base", "a");
 
+        KorapResult kr = ki.search(sq, (short) 15);
 
-	// Save documents
-	ki.commit();
+        assertEquals("totalResults", kr.getTotalResults(), 12);
+        assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
+        assertEquals("EndPos (0)", 0, kr.getMatch(0).endPos);
+        assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
+        assertEquals("EndPos (1)", 0, kr.getMatch(1).endPos);
+        assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
+        assertEquals("EndPos (2)", 0, kr.getMatch(2).endPos);
+        assertEquals("StartPos (3)", 0, kr.getMatch(3).startPos);
+        assertEquals("EndPos (3)", 12, kr.getMatch(3).endPos);
+        assertEquals("StartPos (4)", 1, kr.getMatch(4).startPos);
+        assertEquals("EndPos (4)", 9, kr.getMatch(4).endPos);
+        assertEquals("StartPos (5)", 2, kr.getMatch(5).startPos);
+        assertEquals("EndPos (5)", 6, kr.getMatch(5).endPos);
 
-	assertEquals(6, ki.numberOf("documents"));
-
-	SpanQuery sq = new SpanElementQuery("base", "a");
-
-	KorapResult kr = ki.search(sq, (short) 15);
-
-	assertEquals("totalResults", kr.getTotalResults(), 12);
-
-	assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
-	assertEquals("EndPos (0)", 0, kr.getMatch(0).endPos);
-	assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
-	assertEquals("EndPos (1)", 0, kr.getMatch(1).endPos);
-	assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
-	assertEquals("EndPos (2)", 0, kr.getMatch(2).endPos);
-
-	assertEquals("StartPos (3)", 0, kr.getMatch(3).startPos);
-	assertEquals("EndPos (3)", 12, kr.getMatch(3).endPos);
-	assertEquals("StartPos (4)", 1, kr.getMatch(4).startPos);
-	assertEquals("EndPos (4)", 9, kr.getMatch(4).endPos);
-	assertEquals("StartPos (5)", 2, kr.getMatch(5).startPos);
-	assertEquals("EndPos (5)", 6, kr.getMatch(5).endPos);
-
-	assertEquals("StartPos (6)", 0, kr.getMatch(6).startPos);
-	assertEquals("EndPos (6)", 12, kr.getMatch(6).endPos);
-	assertEquals("StartPos (7)", 1, kr.getMatch(7).startPos);
-	assertEquals("EndPos (7)", 9, kr.getMatch(7).endPos);
-	assertEquals("StartPos (8)", 2, kr.getMatch(8).startPos);
-	assertEquals("EndPos (8)", 6, kr.getMatch(8).endPos);
-
-	assertEquals("StartPos (9)", 0, kr.getMatch(9).startPos);
-	assertEquals("EndPos (9)", 3, kr.getMatch(9).endPos);
-	assertEquals("StartPos (10)", 0, kr.getMatch(10).startPos);
-	assertEquals("EndPos (10)", 6, kr.getMatch(10).endPos);
-	assertEquals("StartPos (11)", 0, kr.getMatch(11).startPos);
-	assertEquals("EndPos (11)", 9, kr.getMatch(11).endPos);
+        assertEquals("StartPos (6)", 0, kr.getMatch(6).startPos);
+        assertEquals("EndPos (6)", 12, kr.getMatch(6).endPos);
+        assertEquals("StartPos (7)", 1, kr.getMatch(7).startPos);
+        assertEquals("EndPos (7)", 9, kr.getMatch(7).endPos);
+        assertEquals("StartPos (8)", 2, kr.getMatch(8).startPos);
+        assertEquals("EndPos (8)", 6, kr.getMatch(8).endPos);
+        
+        assertEquals("StartPos (9)", 0, kr.getMatch(9).startPos);
+        assertEquals("EndPos (9)", 3, kr.getMatch(9).endPos);
+        assertEquals("StartPos (10)", 0, kr.getMatch(10).startPos);
+        assertEquals("EndPos (10)", 6, kr.getMatch(10).endPos);
+        assertEquals("StartPos (11)", 0, kr.getMatch(11).startPos);
+        assertEquals("EndPos (11)", 9, kr.getMatch(11).endPos);
     };
 
     @Test
     public void indexExample3Offsets () throws IOException {
-	KorapIndex ki = new KorapIndex();
+        KorapIndex ki = new KorapIndex();
 
-	// Er schrie: <s>"Das war ich!"</s>
-	FieldDocument fd = new FieldDocument();
-	fd = new FieldDocument();
-	fd.addTV("base",
-		 "Er schrie: \"Das war ich!\" und ging.",
-		 "[(0-2)s:Er|_0#0-3]" +
-		 "[(3-9)s:schrie|_1#3-9]" +
-		 "[(12-15)s:Das|_2#12-15|<>:sentence#11-25$<i>5]" +
-		 "[(16-19)s:war|_3#16-19]" +
-		 "[(20-23)s:ich|_4#20-23]" +
-		 "[(26-29)s:und|_5#26-29]" +
-		 "[(30-34)s:ging|_6#30-34]");
-	ki.addDoc(fd);
+        // Er schrie: <s>"Das war ich!"</s>
+        FieldDocument fd = new FieldDocument();
+        fd = new FieldDocument();
+        fd.addTV("base",
+                 "Er schrie: \"Das war ich!\" und ging.",
+                 "[(0-2)s:Er|_0#0-3]" +
+                 "[(3-9)s:schrie|_1#3-9]" +
+                 "[(12-15)s:Das|_2#12-15|<>:sentence#11-25$<i>5]" +
+                 "[(16-19)s:war|_3#16-19]" +
+                 "[(20-23)s:ich|_4#20-23]" +
+                 "[(26-29)s:und|_5#26-29]" +
+                 "[(30-34)s:ging|_6#30-34]");
+        ki.addDoc(fd);
 
-	// Save documents
-	ki.commit();
+        // Save documents
+        ki.commit();
+        
+        SpanQuery sq = new SpanClassQuery(new SpanElementQuery("base", "sentence"), (byte)3);
+        KorapResult kr;
+        kr = ki.search(sq, 0, (short) 15, true, (short) 1, true, (short) 1);
+        assertEquals("totalResults", kr.getTotalResults(), 1);
+        
+        assertEquals("... schrie: [\"{3:Das war ich}!\"] und ...",kr.getMatch(0).getSnippetBrackets());
+        assertEquals("<span class=\"context-left\"><span class=\"more\"></span>schrie: </span><span class=\"match\">&quot;<em class=\"class-3 level-0\">Das war ich</em>!&quot;</span><span class=\"context-right\"> und<span class=\"more\"></span></span>",kr.getMatch(0).getSnippetHTML());
 
-	SpanQuery sq = new SpanClassQuery(new SpanElementQuery("base", "sentence"), (byte)3);
-	KorapResult kr;
-	kr = ki.search(sq, 0, (short) 15, true, (short) 1, true, (short) 1);
-	assertEquals("totalResults", kr.getTotalResults(), 1);
+        kr = ki.search(sq, 0, (short) 15, true, (short) 0, true, (short) 0);
+        assertEquals("... [\"{3:Das war ich}!\"] ...",kr.getMatch(0).getSnippetBrackets());
+        assertEquals("totalResults", kr.getTotalResults(), 1);
 
-	assertEquals("... schrie: [\"{3:Das war ich}!\"] und ...",kr.getMatch(0).getSnippetBrackets());
-	assertEquals("<span class=\"context-left\"><span class=\"more\"></span>schrie: </span><span class=\"match\">&quot;<em class=\"class-3 level-0\">Das war ich</em>!&quot;</span><span class=\"context-right\"> und<span class=\"more\"></span></span>",kr.getMatch(0).getSnippetHTML());
+        kr = ki.search(sq, 0, (short) 15, true, (short) 6, true, (short) 6);
+        assertEquals("Er schrie: [\"{3:Das war ich}!\"] und ging.",kr.getMatch(0).getSnippetBrackets());
+        assertEquals("totalResults", kr.getTotalResults(), 1);
 
+        kr = ki.search(sq, 0, (short) 15, true, (short) 2, true, (short) 2);
+        assertEquals("Er schrie: [\"{3:Das war ich}!\"] und ging ...",kr.getMatch(0).getSnippetBrackets());
+        assertEquals("totalResults", kr.getTotalResults(), 1);
 
-	kr = ki.search(sq, 0, (short) 15, true, (short) 0, true, (short) 0);
-	assertEquals("... [\"{3:Das war ich}!\"] ...",kr.getMatch(0).getSnippetBrackets());
-	assertEquals("totalResults", kr.getTotalResults(), 1);
+        sq = new SpanClassQuery(
+            new SpanWithinQuery(
+                new SpanElementQuery("base", "sentence"),
+                new SpanClassQuery(
+                    new SpanTermQuery(new Term("base", "s:Das")), (byte) 2
+                )
+            ),
+            (byte) 1
+        );
 
+        kr = ki.search(sq, (short) 15);
+        assertEquals("Er schrie: [\"{1:{2:Das} war ich}!\"] und ging.",kr.getMatch(0).getSnippetBrackets());
+        assertEquals("totalResults", kr.getTotalResults(), 1);
 
-	kr = ki.search(sq, 0, (short) 15, true, (short) 6, true, (short) 6);
-	assertEquals("Er schrie: [\"{3:Das war ich}!\"] und ging.",kr.getMatch(0).getSnippetBrackets());
-	assertEquals("totalResults", kr.getTotalResults(), 1);
+        sq = new SpanClassQuery(
+            new SpanWithinQuery(
+                new SpanElementQuery("base", "sentence"),
+                new SpanClassQuery(
+                    new SpanTermQuery(new Term("base", "s:war")), (byte) 2
+                )
+            ),
+            (byte) 1
+        );
 
-	kr = ki.search(sq, 0, (short) 15, true, (short) 2, true, (short) 2);
-	assertEquals("Er schrie: [\"{3:Das war ich}!\"] und ging ...",kr.getMatch(0).getSnippetBrackets());
-	assertEquals("totalResults", kr.getTotalResults(), 1);
+        kr = ki.search(sq, (short) 15);
+        assertEquals("Er schrie: [\"{1:Das {2:war} ich}!\"] und ging.",kr.getMatch(0).getSnippetBrackets());
+        assertEquals("totalResults", kr.getTotalResults(), 1);
 
+        sq = new SpanClassQuery(
+            new SpanWithinQuery(
+                new SpanElementQuery("base", "sentence"),
+                new SpanClassQuery(
+                    new SpanTermQuery(new Term("base", "s:ich")), (byte) 2
+                )
+            ),
+            (byte) 1
+        );
+        
+        kr = ki.search(sq, (short) 15);
+        assertEquals("Er schrie: [\"{1:Das war {2:ich}}!\"] und ging.",kr.getMatch(0).getSnippetBrackets());
+        assertEquals("totalResults", kr.getTotalResults(), 1);
 
-	sq = new SpanClassQuery(
-          new SpanWithinQuery(
-            new SpanElementQuery("base", "sentence"),
-	    new SpanClassQuery(
-              new SpanTermQuery(new Term("base", "s:Das")), (byte) 2
-	    )
-        ), (byte) 1);
+        sq = new SpanClassQuery(
+            new SpanWithinQuery(
+                new SpanElementQuery("base", "sentence"),
+                new SpanClassQuery(
+                    new SpanTermQuery(new Term("base", "s:und")), (byte) 2
+                )
+            ),
+            (byte) 1
+        );
 
-	kr = ki.search(sq, (short) 15);
-	assertEquals("Er schrie: [\"{1:{2:Das} war ich}!\"] und ging.",kr.getMatch(0).getSnippetBrackets());
-	assertEquals("totalResults", kr.getTotalResults(), 1);
+        kr = ki.search(sq, (short) 15);
+        assertEquals("totalResults", kr.getTotalResults(), 0);
 
-	sq = new SpanClassQuery(
-          new SpanWithinQuery(
-            new SpanElementQuery("base", "sentence"),
-	    new SpanClassQuery(
-              new SpanTermQuery(new Term("base", "s:war")), (byte) 2
-	    )
-        ), (byte) 1);
+        sq = new SpanClassQuery(
+            new SpanWithinQuery(
+                new SpanElementQuery("base", "sentence"),
+                new SpanClassQuery(
+                    new SpanTermQuery(new Term("base", "s:schrie")), (byte) 2
+                )
+            ),
+            (byte) 1
+        );
 
-	kr = ki.search(sq, (short) 15);
-	assertEquals("Er schrie: [\"{1:Das {2:war} ich}!\"] und ging.",kr.getMatch(0).getSnippetBrackets());
-	assertEquals("totalResults", kr.getTotalResults(), 1);
-
-	sq = new SpanClassQuery(
-          new SpanWithinQuery(
-            new SpanElementQuery("base", "sentence"),
-	    new SpanClassQuery(
-              new SpanTermQuery(new Term("base", "s:ich")), (byte) 2
-	    )
-        ), (byte) 1);
-
-	kr = ki.search(sq, (short) 15);
-	assertEquals("Er schrie: [\"{1:Das war {2:ich}}!\"] und ging.",kr.getMatch(0).getSnippetBrackets());
-	assertEquals("totalResults", kr.getTotalResults(), 1);
-
-	sq = new SpanClassQuery(
-          new SpanWithinQuery(
-            new SpanElementQuery("base", "sentence"),
-	    new SpanClassQuery(
-              new SpanTermQuery(new Term("base", "s:und")), (byte) 2
-	    )
-        ), (byte) 1);
-
-	kr = ki.search(sq, (short) 15);
-	assertEquals("totalResults", kr.getTotalResults(), 0);
-
-	sq = new SpanClassQuery(
-          new SpanWithinQuery(
-            new SpanElementQuery("base", "sentence"),
-	    new SpanClassQuery(
-              new SpanTermQuery(new Term("base", "s:schrie")), (byte) 2
-	    )
-        ), (byte) 1);
-
-	kr = ki.search(sq, (short) 15);
-	assertEquals("totalResults", kr.getTotalResults(), 0);
+        kr = ki.search(sq, (short) 15);
+        assertEquals("totalResults", kr.getTotalResults(), 0);
     };
 
-    //!! Offset is 1 token tooo long
-
     @Test
     public void indexExample4 () throws IOException {
-	KorapIndex ki = new KorapIndex();
+        KorapIndex ki = new KorapIndex();
 
-	// Case 1, 6, 7, 13
-	// xy<a><a>x</a>b<a>c</a></a>x
-	FieldDocument fd = new FieldDocument();
-	fd.addTV("base",
-		 "x  y  x  b  c  x  ",
-		 "[(0-3)s:x|_0#0-3]" +
-		 "[(3-6)s:y|_1#3-6]" +
-		 "[(6-9)s:x|_2#6-9|<>:a#6-15$<i>5|<>:a#6-9$<i>3]" +
-		 "[(9-12)s:b|_3#9-12]" +
-		 "[(12-15)s:c|_4#12-15|<>:a#12-15$<i>5]" +
-		 "[(15-18)s:x|_5#15-18]");
-	ki.addDoc(fd);
+        // Case 1, 6, 7, 13
+        // xy<a><a>x</a>b<a>c</a></a>x
+        FieldDocument fd = new FieldDocument();
+        fd.addTV("base",
+                 "x  y  x  b  c  x  ",
+                 "[(0-3)s:x|_0#0-3]" +
+                 "[(3-6)s:y|_1#3-6]" +
+                 "[(6-9)s:x|_2#6-9|<>:a#6-15$<i>5|<>:a#6-9$<i>3]" +
+                 "[(9-12)s:b|_3#9-12]" +
+                 "[(12-15)s:c|_4#12-15|<>:a#12-15$<i>5]" +
+                 "[(15-18)s:x|_5#15-18]");
+        ki.addDoc(fd);
 
-	// Save documents
-	ki.commit();
+        // Save documents
+        ki.commit();
 
-	assertEquals(1, ki.numberOf("documents"));
+        assertEquals(1, ki.numberOf("documents"));
 
-	SpanQuery sq = new SpanWithinQuery(
-	    new SpanElementQuery("base", "a"),
+        SpanQuery sq = new SpanWithinQuery(
+            new SpanElementQuery("base", "a"),
             new SpanTermQuery(new Term("base", "s:x"))
         );
 
-	KorapResult kr = ki.search(sq, (short) 10);
+        KorapResult kr = ki.search(sq, (short) 10);
 
-	assertEquals("totalResults", kr.getTotalResults(), 2);
-	assertEquals("StartPos (0)", 2, kr.getMatch(0).startPos);
-	assertEquals("EndPos (0)", 3, kr.getMatch(0).endPos);
-	assertEquals("StartPos (1)", 2, kr.getMatch(1).startPos);
-	assertEquals("EndPos (1)", 5, kr.getMatch(1).endPos);
+        assertEquals("totalResults", kr.getTotalResults(), 2);
+        assertEquals("StartPos (0)", 2, kr.getMatch(0).startPos);
+        assertEquals("EndPos (0)", 3, kr.getMatch(0).endPos);
+        assertEquals("StartPos (1)", 2, kr.getMatch(1).startPos);
+        assertEquals("EndPos (1)", 5, kr.getMatch(1).endPos);
     };
 
-
     @Test
     public void indexExample5 () throws IOException {
-	// 1,2,3,6,9,10,12
-	KorapIndex ki = new KorapIndex();
+        // 1,2,3,6,9,10,12
+        KorapIndex ki = new KorapIndex();
 
-	// hij<a>hi<a>h<a>ij</a></a>hi</a>
-	FieldDocument fd = new FieldDocument();
-	fd.addTV("base",
-		 "hijhihijhi",
-		 "[(0-1)s:h|i:h|_0#0-1|-:a$<i>3|-:t$<i>10]" +
-		 "[(1-2)s:i|i:i|_1#1-2]" +
-		 "[(2-3)s:j|i:j|_2#2-3]" +
-		 "[(3-4)s:h|i:h|_3#3-4|<>:a#3-10$<i>10]" +
-		 "[(4-5)s:i|i:i|_4#4-5]" +
-		 "[(5-6)s:h|i:h|_5#5-6|<>:a#5-8$<i>8]" +
-		 "[(6-7)s:i|i:i|_6#6-7|<>:a#6-8$<i>8]" +
-		 "[(7-8)s:j|i:j|_7#7-8]" +
-		 "[(8-9)s:h|i:h|_8#8-9]" +
-		 "[(9-10)s:i|i:i|_9#9-10]");
-	ki.addDoc(fd);
+        // hij<a>hi<a>h<a>ij</a></a>hi</a>
+        FieldDocument fd = new FieldDocument();
+        fd.addTV("base",
+                 "hijhihijhi",
+                 "[(0-1)s:h|i:h|_0#0-1|-:a$<i>3|-:t$<i>10]" +
+                 "[(1-2)s:i|i:i|_1#1-2]" +
+                 "[(2-3)s:j|i:j|_2#2-3]" +
+                 "[(3-4)s:h|i:h|_3#3-4|<>:a#3-10$<i>10]" +
+                 "[(4-5)s:i|i:i|_4#4-5]" +
+                 "[(5-6)s:h|i:h|_5#5-6|<>:a#5-8$<i>8]" +
+                 "[(6-7)s:i|i:i|_6#6-7|<>:a#6-8$<i>8]" +
+                 "[(7-8)s:j|i:j|_7#7-8]" +
+                 "[(8-9)s:h|i:h|_8#8-9]" +
+                 "[(9-10)s:i|i:i|_9#9-10]");
+        ki.addDoc(fd);
 
-	// Save documents
-	ki.commit();
+        // Save documents
+        ki.commit();
 
-	assertEquals(1, ki.numberOf("documents"));
+        assertEquals(1, ki.numberOf("documents"));
 
-	SpanQuery sq = new SpanWithinQuery(
-	    new SpanElementQuery("base", "a"),
+        SpanQuery sq = new SpanWithinQuery(
+            new SpanElementQuery("base", "a"),
             new SpanNextQuery(
-	      new SpanTermQuery(new Term("base", "s:h")),
-	      new SpanTermQuery(new Term("base", "s:i"))
+                new SpanTermQuery(new Term("base", "s:h")),
+                new SpanTermQuery(new Term("base", "s:i"))
             )
         );
 
-	KorapResult kr = ki.search(sq, (short) 10);
+        KorapResult kr = ki.search(sq, (short) 10);
 
-	assertEquals("totalResults", kr.getTotalResults(), 4);
+        assertEquals("totalResults", kr.getTotalResults(), 4);
 
-	assertEquals("StartPos (0)", 3, kr.getMatch(0).startPos);
-	assertEquals("EndPos (0)", 10, kr.getMatch(0).endPos);
-	assertEquals("StartPos (1)", 3, kr.getMatch(1).startPos);
-	assertEquals("EndPos (1)", 10, kr.getMatch(1).endPos);
-	assertEquals("StartPos (2)", 3, kr.getMatch(2).startPos);
-	assertEquals("EndPos (2)", 10, kr.getMatch(2).endPos);
-	assertEquals("StartPos (3)", 5, kr.getMatch(3).startPos);
-	assertEquals("EndPos (3)", 8, kr.getMatch(3).endPos);
+        assertEquals("StartPos (0)", 3, kr.getMatch(0).startPos);
+        assertEquals("EndPos (0)", 10, kr.getMatch(0).endPos);
+        assertEquals("StartPos (1)", 3, kr.getMatch(1).startPos);
+        assertEquals("EndPos (1)", 10, kr.getMatch(1).endPos);
+        assertEquals("StartPos (2)", 3, kr.getMatch(2).startPos);
+        assertEquals("EndPos (2)", 10, kr.getMatch(2).endPos);
+        assertEquals("StartPos (3)", 5, kr.getMatch(3).startPos);
+        assertEquals("EndPos (3)", 8, kr.getMatch(3).endPos);
     };
 
     @Test
     public void indexExample6 () throws IOException {
-	KorapIndex ki = new KorapIndex();
-	// 2,5,8,12,13
-	// h<a><a>i</a>j</a><a>h</a>i j<a>h i</a>j
-	FieldDocument fd = new FieldDocument();
-	fd.addTV("base",
-		 "hijhi jh ij",
-		 "[(0-1)s:h|i:h|_0#0-1|-:a$<i>4|-:t$<i>9]" +
-		 "[(1-2)s:i|i:i|_1#1-2|<>:a#1-2$<i>2|<>:a#1-3$<i>3]" +
-		 "[(2-3)s:j|i:j|_2#2-3]" +
-		 "[(3-4)s:h|i:h|_3#3-4|<>:a#3-4$<i>4]" +
-		 "[(4-5)s:i|i:i|_4#4-5]" +
-		 "[(6-7)s:j|i:j|_5#6-7]" +
-		 "[(7-8)s:h|i:h|_6#7-8|<>:a#7-10$<i>8]" +
-		 "[(9-10)s:i|i:i|_7#9-10]" +
-		 "[(10-11)s:j|i:j|_8#10-11]");
-	ki.addDoc(fd);
+        KorapIndex ki = new KorapIndex();
+        // 2,5,8,12,13
+        // h<a><a>i</a>j</a><a>h</a>i j<a>h i</a>j
+        FieldDocument fd = new FieldDocument();
+        fd.addTV("base",
+                 "hijhi jh ij",
+                 "[(0-1)s:h|i:h|_0#0-1|-:a$<i>4|-:t$<i>9]" +
+                 "[(1-2)s:i|i:i|_1#1-2|<>:a#1-2$<i>2|<>:a#1-3$<i>3]" +
+                 "[(2-3)s:j|i:j|_2#2-3]" +
+                 "[(3-4)s:h|i:h|_3#3-4|<>:a#3-4$<i>4]" +
+                 "[(4-5)s:i|i:i|_4#4-5]" +
+                 "[(6-7)s:j|i:j|_5#6-7]" +
+                 "[(7-8)s:h|i:h|_6#7-8|<>:a#7-10$<i>8]" +
+                 "[(9-10)s:i|i:i|_7#9-10]" +
+                 "[(10-11)s:j|i:j|_8#10-11]");
+        ki.addDoc(fd);
 
-	// Save documents
-	ki.commit();
+        // Save documents
+        ki.commit();
 
-	assertEquals(1, ki.numberOf("documents"));
+        assertEquals(1, ki.numberOf("documents"));
 
-	SpanQuery sq = new SpanWithinQuery(
-          new SpanElementQuery("base", "a"),
+        SpanQuery sq = new SpanWithinQuery(
+            new SpanElementQuery("base", "a"),
             new SpanNextQuery(
-	      new SpanTermQuery(new Term("base", "s:h")),
-	      new SpanNextQuery(
-		new SpanTermQuery(new Term("base", "s:i")),
-  	        new SpanTermQuery(new Term("base", "s:j"))
-	      )
+                new SpanTermQuery(new Term("base", "s:h")),
+                new SpanNextQuery(
+                    new SpanTermQuery(new Term("base", "s:i")),
+                    new SpanTermQuery(new Term("base", "s:j"))
+                )
             )
         );
 
-	KorapResult kr = ki.search(sq, (short) 10);
-
-	assertEquals("totalResults", kr.getTotalResults(), 0);
+        KorapResult kr = ki.search(sq, (short) 10);
+        assertEquals("totalResults", kr.getTotalResults(), 0);
     };
 
 
     @Test
     public void indexExample7 () throws IOException {
-	KorapIndex ki = new KorapIndex();
-	// 4,5,11,13
-	// x<a>x h</a>i j h<a>i j</a>
-	FieldDocument fd = new FieldDocument();
-	fd.addTV("base",
-		 "xx hi j hi j",
-		 "[(0-1)s:x|i:x|_0#0-1|-:a$<i>2|-:t$<i>8]" +
-		 "[(1-2)s:x|i:x|_1#1-2|<>:a#1-4$<i>3]" +
-		 "[(3-4)s:h|i:h|_2#3-4]" +
-		 "[(4-5)s:i|i:i|_3#4-5]" +
-		 "[(6-7)s:j|i:j|_4#6-7]" +
-		 "[(8-9)s:h|i:h|_5#8-9]" +
-		 "[(9-10)s:i|i:i|_6#9-10|<>:a#9-12$<i>8]" +
-		 "[(11-12)s:j|i:j|_7#11-12]");
-	ki.addDoc(fd);
+        KorapIndex ki = new KorapIndex();
+        // 4,5,11,13
+        // x<a>x h</a>i j h<a>i j</a>
+        FieldDocument fd = new FieldDocument();
+        fd.addTV("base",
+                 "xx hi j hi j",
+                 "[(0-1)s:x|i:x|_0#0-1|-:a$<i>2|-:t$<i>8]" +
+                 "[(1-2)s:x|i:x|_1#1-2|<>:a#1-4$<i>3]" +
+                 "[(3-4)s:h|i:h|_2#3-4]" +
+                 "[(4-5)s:i|i:i|_3#4-5]" +
+                 "[(6-7)s:j|i:j|_4#6-7]" +
+                 "[(8-9)s:h|i:h|_5#8-9]" +
+                 "[(9-10)s:i|i:i|_6#9-10|<>:a#9-12$<i>8]" +
+                 "[(11-12)s:j|i:j|_7#11-12]");
+        ki.addDoc(fd);
 
-	// Save documents
-	ki.commit();
+        // Save documents
+        ki.commit();
 
-	assertEquals(1, ki.numberOf("documents"));
+        assertEquals(1, ki.numberOf("documents"));
 
-	SpanQuery sq = new SpanWithinQuery(
-          new SpanElementQuery("base", "a"),
+        SpanQuery sq = new SpanWithinQuery(
+            new SpanElementQuery("base", "a"),
             new SpanNextQuery(
-	      new SpanTermQuery(new Term("base", "s:h")),
-	      new SpanNextQuery(
-		new SpanTermQuery(new Term("base", "s:i")),
-  	        new SpanTermQuery(new Term("base", "s:j"))
-	      )
+                new SpanTermQuery(new Term("base", "s:h")),
+                new SpanNextQuery(
+                    new SpanTermQuery(new Term("base", "s:i")),
+                    new SpanTermQuery(new Term("base", "s:j"))
+                )
             )
         );
 
-	KorapResult kr = ki.search(sq, (short) 10);
-
-	assertEquals("totalResults", kr.getTotalResults(), 0);
+        KorapResult kr = ki.search(sq, (short) 10);
+        
+        assertEquals("totalResults", kr.getTotalResults(), 0);
     };
     
-    /** SpanElementQueries 
-     * */
+
+    /** SpanElementQueries */
     @Test
     public void indexExample8() throws IOException{	   
-	KorapIndex ki = new KorapIndex();		
-	FieldDocument fd = new FieldDocument();
-	// <a>xx <e>hi j <e>hi j</e></e></a>
-	fd.addTV("base",
-		 "xx hi j hi j",
-		 "[(0-1)s:x|i:x|_0#0-1|<>:a#1-12$<i>8]" +
-		 "[(1-2)s:x|i:x|_1#1-2]" +
-		 "[(3-4)s:h|i:h|_2#3-4|<>:e#3-12$<i>8]" +
-		 "[(4-5)s:i|i:i|_3#4-5]" +
-		 "[(6-7)s:j|i:j|_4#6-7]" +
-		 "[(8-9)s:h|i:h|_5#8-9|<>:e#8-9$<i>8]" +
-		 "[(9-10)s:i|i:i|_6#9-10]" +
-		 "[(11-12)s:j|i:j|_7#11-12]");
-	ki.addDoc(fd);
+        KorapIndex ki = new KorapIndex();		
+        FieldDocument fd = new FieldDocument();
+        // <a>xx <e>hi j <e>hi j</e></e></a>
+        fd.addTV("base",
+                 "xx hi j hi j",
+                 "[(0-1)s:x|i:x|_0#0-1|<>:a#1-12$<i>8]" +
+                 "[(1-2)s:x|i:x|_1#1-2]" +
+                 "[(3-4)s:h|i:h|_2#3-4|<>:e#3-12$<i>8]" +
+                 "[(4-5)s:i|i:i|_3#4-5]" +
+                 "[(6-7)s:j|i:j|_4#6-7]" +
+                 "[(8-9)s:h|i:h|_5#8-9|<>:e#8-9$<i>8]" +
+                 "[(9-10)s:i|i:i|_6#9-10]" +
+                 "[(11-12)s:j|i:j|_7#11-12]");
+        ki.addDoc(fd);
     };
     
-	/**
-	 * @throws IOException */
+
+    // contains(<s>, (es wird | wird es))
     @Test
     public void queryJSONpoly2() throws QueryException, IOException {
-	
-	String jsonPath = getClass().getResource("/queries/poly2.json").getFile();
-	String jsonPQuery = readFile(jsonPath);		
-	SpanQueryWrapper sqwi = new KorapQuery("tokens").fromJson(
-								  jsonPQuery
-								  );
+        String jsonPath = getClass().getResource("/queries/poly2.json").getFile();
+        String jsonPQuery = readFile(jsonPath);		
+        SpanQueryWrapper sqwi = new KorapQuery("tokens").fromJson(jsonPQuery);
 		
-	SpanWithinQuery sq = (SpanWithinQuery) sqwi.toQuery();
-	//		System.out.println(sq.toString());
+        SpanWithinQuery sq = (SpanWithinQuery) sqwi.toQuery();
 		
-	KorapIndex ki = new KorapIndex();
-	ki.addDocFile(
-		      getClass().getResource("/wiki/DDD-08370.json.gz").getFile(),true);
-	ki.addDocFile(
-		      getClass().getResource("/wiki/PPP-02924.json.gz").getFile(),true);
-	ki.commit();
-	try {
-	    KorapResult kr = ki.search(sq, (short) 10);
-	    assertEquals(2, kr.getTotalResults());
-	    assertEquals(0, kr.getMatch(0).getLocalDocID());
-	    assertEquals(76, kr.getMatch(0).getStartPos());
-	    assertEquals(93, kr.getMatch(0).getEndPos());
-	    assertEquals(1, kr.getMatch(0).getLocalDocID());
-	    assertEquals(237, kr.getMatch(1).getStartPos());
-	    assertEquals(252, kr.getMatch(1).getEndPos());
-	}
+        KorapIndex ki = new KorapIndex();
 
-	catch (Exception e) {
-	    fail("Nullpointer (known)");
-	};
-//		for (KorapMatch km : kr.getMatches()){		
-//			System.out.println(km.getStartPos() +","+km.getEndPos()+" "
-//				+km.getSnippetBrackets());
-//		}		
-	
-    }
+        ki.addDocFile(
+            getClass().getResource("/wiki/DDD-08370.json.gz").getFile(),
+            true
+        );
+        ki.addDocFile(
+            getClass().getResource("/wiki/PPP-02924.json.gz").getFile(),
+            true
+        );
+
+        ki.commit();
+        KorapResult kr = ki.search(sq, (short) 10);
+        assertEquals(2, kr.getTotalResults());
+        assertEquals(0, kr.getMatch(0).getLocalDocID());
+        assertEquals(76, kr.getMatch(0).getStartPos());
+        assertEquals(93, kr.getMatch(0).getEndPos());
+        assertEquals(1, kr.getMatch(1).getLocalDocID());
+        assertEquals(237, kr.getMatch(1).getStartPos());
+        assertEquals(252, kr.getMatch(1).getEndPos());
+
+        /*
+		for (KorapMatch km : kr.getMatches()){		
+			System.out.println(km.getStartPos() +","+km.getEndPos()+" "
+                               +km.getSnippetBrackets());
+		};	
+*/
+    };
 	
 	
     private String readFile(String path) {
-	StringBuilder sb = new StringBuilder();
-	try {
-	    BufferedReader in = new BufferedReader(new FileReader(path));
-	    String str;
-	    while ((str = in.readLine()) != null) {
-		sb.append(str);
-	    };
-	    in.close();
-	} catch (IOException e) {
-	    fail(e.getMessage());
-	}
-	return sb.toString();
+        StringBuilder sb = new StringBuilder();
+        try {
+            BufferedReader in = new BufferedReader(new FileReader(path));
+            String str;
+            while ((str = in.readLine()) != null) {
+                sb.append(str);
+            };
+            in.close();
+        } catch (IOException e) {
+            fail(e.getMessage());
+        }
+        return sb.toString();
     };
 };
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestFrameConstraint.java b/src/test/java/de/ids_mannheim/korap/query/TestFrameConstraint.java
index 37f038d..019c949 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestFrameConstraint.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestFrameConstraint.java
@@ -49,7 +49,7 @@
         assertEquals(fc.check("succeeds"),         false);
 
         // Some or
-        fc.or("succeeds").or("succeedsDirectly");
+        fc.add("succeeds").add("succeedsDirectly");
         assertEquals(fc.check("precedes"),         false);
         assertEquals(fc.check("precedesDirectly"), false);
         assertEquals(fc.check("overlapsLeft"),     false);
@@ -65,7 +65,7 @@
         assertEquals(fc.check("succeeds"),         true);
 
         // Moar or
-        fc.or("precedes").or("precedesDirectly");
+        fc.add("precedes").add("precedesDirectly");
         assertEquals(fc.check("precedes"),         true);
         assertEquals(fc.check("precedesDirectly"), true);
         assertEquals(fc.check("overlapsLeft"),     false);
@@ -81,7 +81,7 @@
         assertEquals(fc.check("succeeds"),         true);
 
         // Moar or
-        fc.or("matches").or("startsWith");
+        fc.add("matches").add("startsWith");
         assertEquals(fc.check("precedes"),         true);
         assertEquals(fc.check("precedesDirectly"), true);
         assertEquals(fc.check("overlapsLeft"),     false);
@@ -112,11 +112,10 @@
         assertEquals(fc.check("succeedsDirectly"), false);
         assertEquals(fc.check("succeeds"),         false);
 
-
-        fc.or("precedes").
-            or("precedesDirectly").
-            or("startsWith").
-            or("matches");
+        fc.add("precedes").
+            add("precedesDirectly").
+            add("startsWith").
+            add("matches");
         assertEquals(fc.check("precedes"),         true);
         assertEquals(fc.check("precedesDirectly"), true);
         assertEquals(fc.check("overlapsLeft"),     true);
@@ -131,8 +130,8 @@
         assertEquals(fc.check("succeedsDirectly"), false);
         assertEquals(fc.check("succeeds"),         false);
 
-        fc.or("succeeds").
-            or("succeedsDirectly");
+        fc.add("succeeds").
+            add("succeedsDirectly");
         assertEquals(fc.check("precedes"),         true);
         assertEquals(fc.check("precedesDirectly"), true);
         assertEquals(fc.check("overlapsLeft"),     true);
@@ -152,7 +151,7 @@
     public void testOrVector () throws QueryException {
         FrameConstraint fc1 = new FrameConstraint();
         // Some or
-        fc1.or("succeeds").or("succeedsDirectly");
+        fc1.add("succeeds").add("succeedsDirectly");
         assertEquals(fc1.check("precedes"),         false);
         assertEquals(fc1.check("precedesDirectly"), false);
         assertEquals(fc1.check("overlapsLeft"),     false);
@@ -168,7 +167,7 @@
         assertEquals(fc1.check("succeeds"),         true);
 
         FrameConstraint fc2 = new FrameConstraint();
-        fc2.or("precedes").or("precedesDirectly");
+        fc2.add("precedes").add("precedesDirectly");
         assertEquals(fc2.check("precedes"),         true);
         assertEquals(fc2.check("precedesDirectly"), true);
         assertEquals(fc2.check("overlapsLeft"),     false);
@@ -183,7 +182,7 @@
         assertEquals(fc2.check("succeedsDirectly"), false);
         assertEquals(fc2.check("succeeds"),         false);
 
-        fc1.or(fc2);
+        fc1.add(fc2);
         assertEquals(fc1.check("precedes"),         true);
         assertEquals(fc1.check("precedesDirectly"), true);
         assertEquals(fc1.check("overlapsLeft"),     false);