Added javadoc comments.
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanElementQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanElementQuery.java
index cbbab44..28df548 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanElementQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanElementQuery.java
@@ -9,94 +9,132 @@
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.SpanTermQuery;
 import org.apache.lucene.search.spans.Spans;
+import org.apache.lucene.search.spans.TermSpans;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.ToStringUtils;
 
 import de.ids_mannheim.korap.query.spans.ElementSpans;
 
-/** 
- * 	@author Nils Diewald, Margaretha
+/**
+ * SpanElementQuery retrieves {@link ElementSpans} which are special
+ * {@link Term Terms} with prefix "<>". Unlike {@link TermSpans} consisting of
+ * only one term, ElementSpans may contains more than one term comprising a
+ * phrase, a clause, a sentence and so on. <br/>
+ * <br/>
+ * Examples of {@link ElementSpans} are
+ * 
+ * <ul>
+ * <li>sentences indexed as <>:s
+ * 
+ * <pre>
+ * SpanElementQuery seq = new SpanElementQuery(&quot;tokens&quot;, &quot;s&quot;);
+ * </pre>
+ * 
+ * </li>
+ * <li>paragraphs indexed as <>:p
+ * 
+ * <pre>
+ * SpanElementQuery seq = new SpanElementQuery(&quot;tokens&quot;, &quot;p&quot;);
+ * </pre>
+ * 
+ * </li>
+ * 
+ * </ul>
+ * 
+ * @author Nils Diewald
+ * @author margaretha
  */
-
-/** Matches spans wrapped by an element. */
 public class SpanElementQuery extends SpanWithIdQuery {
-	//private SpanTermQuery termQuery;
+    // private SpanTermQuery termQuery;
     private static Term elementTerm;
     private String elementStr;
-    
-    /** Constructor. */
-    public SpanElementQuery (String field, String term) {   
-    	super(new SpanTermQuery(
-    			(elementTerm = new Term(field,"<>:"+term))
-    			),
-    		true
-		);
-    	this.elementStr = term;    	
-    	//this.termQuery = (SpanTermQuery) this.getFirstClause();
-    	//this.elementTerm = termQuery.getTerm();
+
+    /**
+     * Constructs a SpanElementQuery for the given term in the given field.
+     * 
+     * @param field a field where a term belongs to
+     * @param term a term
+     */
+    public SpanElementQuery(String field, String term) {
+        super(new SpanTermQuery((elementTerm = new Term(field, "<>:" + term))),
+                true);
+        this.elementStr = term;
+        // this.termQuery = (SpanTermQuery) this.getFirstClause();
+        // this.elementTerm = termQuery.getTerm();
     };
 
     @Override
-    public Spans getSpans(final AtomicReaderContext context,
-			  Bits acceptDocs,
-			  Map<Term,TermContext> termContexts) throws IOException {
-    	return new ElementSpans(this, context, acceptDocs, termContexts);
+    public Spans getSpans(final AtomicReaderContext context, Bits acceptDocs,
+            Map<Term, TermContext> termContexts) throws IOException {
+        return new ElementSpans(this, context, acceptDocs, termContexts);
     };
 
-	public String getElementStr () {
-		return elementStr;
+    /**
+     * Returns the element name or string, for instance "s" for sentence
+     * elements.
+     * 
+     * @return the element name/string.
+     */
+    public String getElementStr() {
+        return elementStr;
     };
 
-    public void setElementStr (String elementStr) {
-    	this.elementStr = elementStr;
+    /**
+     * Sets the element name or string, for instance "s" for sentence elements.
+     * 
+     * @param elementStr the element name or string
+     */
+    public void setElementStr(String elementStr) {
+        this.elementStr = elementStr;
     }
 
-	@Override
-	public SimpleSpanQuery clone() {
-		SpanElementQuery sq = new SpanElementQuery(
-				this.getField(), 
-				this.getElementStr()
-		);
-		sq.setBoost(this.getBoost());
-		return sq;
-	};
-	
+    @Override
+    public SimpleSpanQuery clone() {
+        SpanElementQuery sq = new SpanElementQuery(this.getField(),
+                this.getElementStr());
+        sq.setBoost(this.getBoost());
+        return sq;
+    };
+
     @Override
     public void extractTerms(Set<Term> terms) {
-    	terms.add(elementTerm);
+        terms.add(elementTerm);
     };
 
     @Override
     public String toString(String field) {
-    	StringBuilder buffer = new StringBuilder("<");
-    	buffer.append(getField()).append(':').append(elementStr);
-    	buffer.append(ToStringUtils.boost(getBoost()));
-    	return buffer.append(" />").toString();
+        StringBuilder buffer = new StringBuilder("<");
+        buffer.append(getField()).append(':').append(elementStr);
+        buffer.append(ToStringUtils.boost(getBoost()));
+        return buffer.append(" />").toString();
     };
-    
+
     @Override
     public int hashCode() {
-    	final int prime = 37; // Instead of 31
-    	int result = super.hashCode();
-    	result = prime * result + ((elementStr == null) ? 0 : elementStr.hashCode());
-    	return result;
+        final int prime = 37; // Instead of 31
+        int result = super.hashCode();
+        result = prime * result
+                + ((elementStr == null) ? 0 : elementStr.hashCode());
+        return result;
     };
 
     @Override
     public boolean equals(Object obj) {
-		if (this == obj) return true;
-		//if (!super.equals(obj)) return false;
-		if (getClass() != obj.getClass()) return false;
-		
-		SpanElementQuery other = (SpanElementQuery) obj;
-		if (elementStr == null && other.elementStr != null)
-			return false;
-		else if (!elementStr.equals(other.elementStr))
-		    return false;
-		
-		if (!getField().equals(other.getField()))
-		    return false;
-		return true;
+        if (this == obj)
+            return true;
+        // if (!super.equals(obj)) return false;
+        if (getClass() != obj.getClass())
+            return false;
+
+        SpanElementQuery other = (SpanElementQuery) obj;
+        if (elementStr == null && other.elementStr != null)
+            return false;
+        else if (!elementStr.equals(other.elementStr))
+            return false;
+
+        if (!getField().equals(other.getField()))
+            return false;
+        return true;
     };
- 
+
 };
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanRelationPartQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanRelationPartQuery.java
index 97f1de0..6989a81 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanRelationPartQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanRelationPartQuery.java
@@ -12,123 +12,217 @@
 
 import de.ids_mannheim.korap.query.spans.RelationPartSpans;
 
-/** This query match one part of a relation (either left or right) to certain 
- * 	elements or terms, and return the other part of the relation.	
+/**
+ * This query match a part of a relation (either left or right) to certain
+ * elements or terms. If inversed, the start and end positions of the right part
+ * of the relation are set as positions of the match.
  * 
- * 	@author margaretha
+ * @author margaretha
  * */
-public class SpanRelationPartQuery extends SpanRelationQuery{
-	
-	private static String elementStr = "s"; // default element interval type
-	
-	private SpanElementQuery elementQuery;
-	private boolean matchRight;  // if false, match left
-	private boolean inverseRelation;  // if false, sort result by the left
-	private int window;	
-	
-	public SpanRelationPartQuery(SpanRelationQuery spanRelationQuery,
-			SpanWithIdQuery secondClause, // match tokenWithIdQuery, ElementQuery, RelationQuery
-			boolean matchRight,
-			boolean inverseRelation,
-			boolean collectPayloads) {
-		this(spanRelationQuery, secondClause, elementStr, matchRight, inverseRelation, collectPayloads);		
-	}
-	
-	public SpanRelationPartQuery(SpanRelationQuery spanRelationQuery,
-			SpanWithIdQuery secondClause, 
-			String elementStr,
-			boolean matchRight,
-			boolean inverseRelation,
-			boolean collectPayloads) {
-		super(spanRelationQuery, secondClause, collectPayloads);
-		this.matchRight = matchRight;
-		this.inverseRelation = inverseRelation;
-		elementQuery = new SpanElementQuery(spanRelationQuery.getField(), elementStr);		
-	}
-	
-	public SpanRelationPartQuery(SpanRelationQuery spanRelationQuery,
-			SpanWithIdQuery secondClause, // match tokenWithIdQuery, ElementQuery, RelationQuery
-			int window,
-			boolean matchRight,
-			boolean inverseRelation,
-			boolean collectPayloads) {
-		super(spanRelationQuery, secondClause, collectPayloads);
-		this.matchRight = matchRight;
-		this.inverseRelation = inverseRelation;
-		this.window = window;
-	}
-	
-	@Override
-	public Spans getSpans(AtomicReaderContext context, Bits acceptDocs,
-			Map<Term, TermContext> termContexts) throws IOException {
-			return new RelationPartSpans(this, context, acceptDocs, termContexts);
-	}
-	
-	@Override
-	public SimpleSpanQuery clone() {
-		SpanRelationPartQuery sq = new SpanRelationPartQuery(
-				(SpanRelationQuery) this.firstClause, 
-				(SpanWithIdQuery) this.secondClause,
-				this.elementQuery.getElementStr(),
-				this.matchRight, 
-				this.inverseRelation,
-				this.collectPayloads
-		);		
-		return sq;
-	}
+public class SpanRelationPartQuery extends SpanRelationQuery {
 
-	@Override
-	public String toString(String field) {
-		StringBuilder sb = new StringBuilder();		
-		sb.append("spanRelationWithVariable(");
-		sb.append(firstClause.toString(field));
-		sb.append(",");
-		sb.append(secondClause.toString(field));
-		sb.append(",");
-		sb.append( matchRight ? "matchRight, " : "matchLeft, " );
-		sb.append(",");
-		if (elementQuery != null){
-			sb.append("element:");
-			sb.append(elementQuery.getElementStr());
-		}
-		else {
-			sb.append("window:");
-			sb.append(this.window);
-		}
-		sb.append(")");
-		sb.append(ToStringUtils.boost(getBoost()));
-		return sb.toString();
-	}
+    private static String elementStr = "s"; // default element interval type
 
-	public boolean isMatchRight() {
-		return matchRight;
-	}
+    private SpanElementQuery elementQuery;
+    private boolean matchRight; // if false, match left
+    private boolean inverseRelation; // if false, sort result by the left
+    private int window;
 
-	public void setMatchRight(boolean matchRight) {
-		this.matchRight = matchRight;
-	}
+    /**
+     * Constructs a SpanRelationPartQuery based on the specified
+     * {@link SpanRelationQuery} and {@link SpanWithIdQuery} within a sentence.
+     * 
+     * @param spanRelationQuery a SpanRelationQuery
+     * @param secondClause a SpanWithIdQuery
+     * @param matchRight <code>true</code> if the right side have to be matched
+     *        with the specified SpanWithIdQuery, <code>false</code> otherwise.
+     * @param inverseRelation <code>true</code> if the resulting
+     *        {@link RelationPartSpans} is to be ordered by right side
+     *        positions, <code>false</code> otherwise.
+     * @param collectPayloads a boolean flag representing the value
+     *        <code>true</code> if payloads are to be collected, otherwise
+     *        <code>false</code>.
+     */
+    public SpanRelationPartQuery(SpanRelationQuery spanRelationQuery,
+            SpanWithIdQuery secondClause, // match tokenWithIdQuery, ElementQuery, RelationQuery
+            boolean matchRight, boolean inverseRelation, boolean collectPayloads) {
+        this(spanRelationQuery, secondClause, elementStr, matchRight,
+                inverseRelation, collectPayloads);
+    }
 
-	public boolean isInverseRelation() {
-		return inverseRelation;
-	}
+    /**
+     * Constructs a SpanRelationPartQuery based on the specified
+     * {@link SpanRelationQuery} and {@link SpanWithIdQuery} within a custom
+     * element type specified by the elementStr.
+     * 
+     * @param spanRelationQuery a SpanRelationQuery
+     * @param secondClause a SpanWithIdQuery
+     * @param elementStr a custom element interval type
+     * @param matchRight <code>true</code> if the right side have to be matched
+     *        with the specified SpanWithIdQuery, <code>false</code> otherwise.
+     * @param inverseRelation <code>true</code> if the resulting
+     *        {@link RelationPartSpans} is to be ordered by right side
+     *        positions, <code>false</code> otherwise.
+     * @param collectPayloads a boolean flag representing the value
+     *        <code>true</code> if payloads are to be collected, otherwise
+     *        <code>false</code>.
+     */
+    public SpanRelationPartQuery(SpanRelationQuery spanRelationQuery,
+            SpanWithIdQuery secondClause, String elementStr,
+            boolean matchRight, boolean inverseRelation, boolean collectPayloads) {
+        super(spanRelationQuery, secondClause, collectPayloads);
+        this.matchRight = matchRight;
+        this.inverseRelation = inverseRelation;
+        elementQuery = new SpanElementQuery(spanRelationQuery.getField(),
+                elementStr);
+    }
 
-	public void setInverseRelation(boolean inverseRelation) {
-		this.inverseRelation = inverseRelation;
-	}
+    /**
+     * * Constructs a SpanRelationPartQuery based on the specified
+     * {@link SpanRelationQuery} and {@link SpanWithIdQuery} within a custom
+     * window length (i.e. number of terms / token positions). A window starts
+     * at the same token position as a relation span, and ends at the start +
+     * window length.
+     * 
+     * @param spanRelationQuery a SpanRelationQuery
+     * @param secondClause a SpanWithIdQuery
+     * @param window a window length
+     * @param matchRight <code>true</code> if the right side have to be matched
+     *        with the specified SpanWithIdQuery, <code>false</code> otherwise.
+     * @param inverseRelation <code>true</code> if the resulting
+     *        {@link RelationPartSpans} is to be ordered by right side
+     *        positions, <code>false</code> otherwise.
+     * @param collectPayloads a boolean flag representing the value
+     *        <code>true</code> if payloads are to be collected, otherwise
+     *        <code>false</code>.
+     */
+    public SpanRelationPartQuery(SpanRelationQuery spanRelationQuery,
+            SpanWithIdQuery secondClause, int window, boolean matchRight,
+            boolean inverseRelation, boolean collectPayloads) {
+        super(spanRelationQuery, secondClause, collectPayloads);
+        this.matchRight = matchRight;
+        this.inverseRelation = inverseRelation;
+        this.window = window;
+    }
 
-	public SpanElementQuery getElementQuery() {
-		return elementQuery;
-	}
+    @Override
+    public Spans getSpans(AtomicReaderContext context, Bits acceptDocs,
+            Map<Term, TermContext> termContexts) throws IOException {
+        return new RelationPartSpans(this, context, acceptDocs, termContexts);
+    }
 
-	public void setElementQuery(SpanElementQuery root) {
-		this.elementQuery = root;
-	}
+    @Override
+    public SimpleSpanQuery clone() {
+        SpanRelationPartQuery sq = new SpanRelationPartQuery(
+                (SpanRelationQuery) this.firstClause,
+                (SpanWithIdQuery) this.secondClause,
+                this.elementQuery.getElementStr(), this.matchRight,
+                this.inverseRelation, this.collectPayloads);
+        return sq;
+    }
 
-	public int getWindow() {
-		return window;
-	}
+    @Override
+    public String toString(String field) {
+        StringBuilder sb = new StringBuilder();
+        sb.append("spanRelationWithVariable(");
+        sb.append(firstClause.toString(field));
+        sb.append(",");
+        sb.append(secondClause.toString(field));
+        sb.append(",");
+        sb.append(matchRight ? "matchRight, " : "matchLeft, ");
+        sb.append(",");
+        if (elementQuery != null) {
+            sb.append("element:");
+            sb.append(elementQuery.getElementStr());
+        } else {
+            sb.append("window:");
+            sb.append(this.window);
+        }
+        sb.append(")");
+        sb.append(ToStringUtils.boost(getBoost()));
+        return sb.toString();
+    }
 
-	public void setWindow(int window) {
-		this.window = window;
-	}
+    /**
+     * Tells if the right side of the RelationSpans is to be match.
+     * 
+     * @return <code>true</code> if the right side of the RelationSpans is to be
+     *         match, <code>false</code> otherwise.
+     */
+    public boolean isMatchRight() {
+        return matchRight;
+    }
+
+    /**
+     * Sets which part of the RelationSpans is to be match.
+     * 
+     * @param matchRight <code>true</code> if the right side of the
+     *        RelationSpans is to be match, <code>false</code> otherwise.
+     */
+    public void setMatchRight(boolean matchRight) {
+        this.matchRight = matchRight;
+    }
+
+    /**
+     * Tells if start and end positions of the resulting span should be set from
+     * the right part of the RelationSpans. Normally the start and end positions
+     * of RelationSpans are those of the left part.
+     * 
+     * @return <code>true</code> if the resulting {@link RelationPartSpans} is
+     *         to be ordered by right side positions, <code>false</code>
+     *         otherwise.
+     */
+    public boolean isInverseRelation() {
+        return inverseRelation;
+    }
+
+    /**
+     * Sets if start and end positions of the resulting span should be set from
+     * the right part of the RelationSpans. Normally the start and end positions
+     * of RelationSpans are those of the left part.
+     * 
+     * @param inverseRelation <code>true</code> if the resulting
+     *        {@link RelationPartSpans} is to be ordered by right side
+     *        positions, <code>false</code> otherwise.
+     */
+    public void setInverseRelation(boolean inverseRelation) {
+        this.inverseRelation = inverseRelation;
+    }
+
+    /**
+     * Returns the SpanElementQuery of the custom element interval type.
+     * 
+     * @return the SpanElementQuery of the custom element interval type
+     */
+    public SpanElementQuery getElementQuery() {
+        return elementQuery;
+    }
+
+    /**
+     * Sets the SpanElementQuery of the custom element interval type.
+     * 
+     * @param intervalType the SpanElementQuery of the custom element interval
+     *        type
+     */
+    public void setElementQuery(SpanElementQuery intervalType) {
+        this.elementQuery = intervalType;
+    }
+
+    /**
+     * Returns the custom window length.
+     * 
+     * @return the custom window length.
+     */
+    public int getWindow() {
+        return window;
+    }
+
+    /**
+     * Sets a custom window length.
+     * 
+     * @param window a custom window length
+     */
+    public void setWindow(int window) {
+        this.window = window;
+    }
 }
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanRelationQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanRelationQuery.java
index 27061b9..8706d8f 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanRelationQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanRelationQuery.java
@@ -13,48 +13,88 @@
 
 import de.ids_mannheim.korap.query.spans.RelationSpans;
 
-/** Querying span representing a relation between tokens, elements, 
- * 	or a-token-and-an-element. This class provides two types of query:
- * 	1. querying any relations
- * 	2. querying relations matching certain type of sources/targets, 
- * 	   that are the left or the right sides of the relations. 
- *  
- *  @author margaretha
+/**
+ * SpanRelationQuery retrieves spans representing a relation between tokens,
+ * elements, or a-token-and-an-element. Relation are marked with prefix "<" or
+ * ">". The direction of the angle bracket represents the direction of the 
+ * corresponding relation. <br/><br/>
+ * 
+ * This class provides two types of query:
+ * <ol>
+ * <li>querying any relations, for instance dependency relation "<:xip/syntax-dep_rel".
+ * 
+ * <pre>SpanRelationQuery sq = new SpanRelationQuery(
+ *          new SpanTermQuery(
+ *              new Term("tokens","<:xip/syntax-dep_rel")),
+ *          true); 
+ * </pre>
+ * </li>
+ * <li>querying relations matching a certain type of sources/targets, that are the
+ * left or the right sides of the relations. This query is used within 
+ * {@link SpanRelationPartQuery}, for instance, to retrieve all dependency relations 
+ * "<:xip/syntax-dep_rel" whose sources (right side) are noun phrases. 
+ * <pre>
+ * SpanRelationPartQuery rv =
+ *      new SpanRelationPartQuery(sq, new SpanElementQuery("tokens","np"), true, 
+ *      false, true);
+ * </pre>
+ * </li>
+ * 
+ * </ol>
+ * 
+ * @author margaretha
  * */
 public class SpanRelationQuery extends SpanWithIdQuery {
 
-	public SpanRelationQuery(SpanQuery firstClause, boolean collectPayloads) {
-		super(firstClause, collectPayloads);
-	}
-	
-	// for spanRelationWithVariable
-	public SpanRelationQuery(SpanRelationQuery spanRelationQuery,
-			SpanQuery secondClause, boolean collectPayloads) {
-		super(spanRelationQuery, secondClause, collectPayloads);
-	}
+    /**
+     * Constructs a SpanRelationQuery based on the given span query.
+     * 
+     * @param firstClause a SpanQuery.
+     * @param collectPayloads a boolean flag representing the value
+     *        <code>true</code> if payloads are to be collected, otherwise
+     *        <code>false</code>.
+     */
+    public SpanRelationQuery(SpanQuery firstClause, boolean collectPayloads) {
+        super(firstClause, collectPayloads);
+    }
 
-	@Override
-	public SimpleSpanQuery clone() {
-		SimpleSpanQuery sq = new SpanRelationQuery(
-				(SpanQuery) this.firstClause.clone(),
-				this.collectPayloads);
-		return sq;
-	}
+    /**
+     * Constructs a SpanRelationQuery which embeds another
+     * {@link SpanRelationQuery}. This is useful for querying a relation having
+     * a specific variable.
+     * 
+     * @param spanRelationQuery a SpanRelationQuery
+     * @param secondClause a SpanQuery
+     * @param collectPayloads a boolean flag representing the value
+     *        <code>true</code> if payloads are to be collected, otherwise
+     *        <code>false</code>.
+     */
+    public SpanRelationQuery(SpanRelationQuery spanRelationQuery,
+            SpanQuery secondClause, boolean collectPayloads) {
+        super(spanRelationQuery, secondClause, collectPayloads);
+    }
 
-	@Override
-	public Spans getSpans(AtomicReaderContext context, Bits acceptDocs,
-			Map<Term, TermContext> termContexts) throws IOException {
-		return new RelationSpans(this, context, acceptDocs, termContexts);
-	}
+    @Override
+    public SimpleSpanQuery clone() {
+        SimpleSpanQuery sq = new SpanRelationQuery(
+                (SpanQuery) this.firstClause.clone(), this.collectPayloads);
+        return sq;
+    }
 
-	@Override
-	public String toString(String field) {
-		StringBuilder sb = new StringBuilder();		
-		sb.append("spanRelation(");
-		sb.append(firstClause.toString(field));
-		sb.append(")");
-		sb.append(ToStringUtils.boost(getBoost()));
-		return sb.toString();
-	}
+    @Override
+    public Spans getSpans(AtomicReaderContext context, Bits acceptDocs,
+            Map<Term, TermContext> termContexts) throws IOException {
+        return new RelationSpans(this, context, acceptDocs, termContexts);
+    }
+
+    @Override
+    public String toString(String field) {
+        StringBuilder sb = new StringBuilder();
+        sb.append("spanRelation(");
+        sb.append(firstClause.toString(field));
+        sb.append(")");
+        sb.append(ToStringUtils.boost(getBoost()));
+        return sb.toString();
+    }
 
 }
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanTermWithIdQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanTermWithIdQuery.java
index 230728a..114d882 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanTermWithIdQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanTermWithIdQuery.java
@@ -12,39 +12,47 @@
 
 import de.ids_mannheim.korap.query.spans.TermSpansWithId;
 
-/** This query wraps the usual SpanTermQuery and returns TermSpans with a spanid property.
- * 	This query is used in other spanqueries that require spans with id as their child spans, 
- * 	for example span relation with variable query.
- * 	
- * 	@author margaretha
+/**
+ * SpanTermWithIdQuery wraps the normal SpanTermQuery and retrieves TermSpans
+ * with a spanid. It is used in other spanqueries requiring spans with id as
+ * their child spans, for example span relation with variable query (
+ * {@link SpanRelationPartQuery}).
+ * 
+ * @author margaretha
  * */
-public class SpanTermWithIdQuery extends SpanWithIdQuery{
+public class SpanTermWithIdQuery extends SpanWithIdQuery {
 
-	public SpanTermWithIdQuery(Term term, boolean collectPayloads) {
-		super(new SpanTermQuery(term), collectPayloads);		
-	}
+    /**
+     * Constructs a SpanTermWithIdQuery for the given term.
+     * 
+     * @param term a {@link Term}
+     * @param collectPayloads a boolean flag representing the value
+     *        <code>true</code> if payloads are to be collected, otherwise
+     *        <code>false</code>.
+     */
+    public SpanTermWithIdQuery(Term term, boolean collectPayloads) {
+        super(new SpanTermQuery(term), collectPayloads);
+    }
 
-	@Override
-	public SimpleSpanQuery clone() {	
-		SpanTermQuery sq = (SpanTermQuery)  this.firstClause;
-		return new SpanTermWithIdQuery(sq.getTerm(), 
-				this.collectPayloads
-		);
-	}
+    @Override
+    public SimpleSpanQuery clone() {
+        SpanTermQuery sq = (SpanTermQuery) this.firstClause;
+        return new SpanTermWithIdQuery(sq.getTerm(), this.collectPayloads);
+    }
 
-	@Override
-	public Spans getSpans(AtomicReaderContext context, Bits acceptDocs,
-			Map<Term, TermContext> termContexts) throws IOException {
-		return new TermSpansWithId(this, context, acceptDocs, termContexts);
-	}
+    @Override
+    public Spans getSpans(AtomicReaderContext context, Bits acceptDocs,
+            Map<Term, TermContext> termContexts) throws IOException {
+        return new TermSpansWithId(this, context, acceptDocs, termContexts);
+    }
 
-	@Override
-	public String toString(String field) {
-		StringBuilder sb = new StringBuilder();		
-		sb.append("spanTermWithId(");
-		sb.append(firstClause.toString(field));
-		sb.append(")");		
-		return sb.toString();
-	}
+    @Override
+    public String toString(String field) {
+        StringBuilder sb = new StringBuilder();
+        sb.append("spanTermWithId(");
+        sb.append(firstClause.toString(field));
+        sb.append(")");
+        return sb.toString();
+    }
 
 }
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanWithAttributeQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanWithAttributeQuery.java
index 2c03fdc..d2e8e6f 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanWithAttributeQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanWithAttributeQuery.java
@@ -12,119 +12,140 @@
 import org.apache.lucene.search.spans.Spans;
 import org.apache.lucene.util.Bits;
 
-import de.ids_mannheim.korap.query.spans.SpansWithAttribute;
 import de.ids_mannheim.korap.query.spans.ElementSpans;
 import de.ids_mannheim.korap.query.spans.RelationSpans;
+import de.ids_mannheim.korap.query.spans.SpansWithAttribute;
 import de.ids_mannheim.korap.query.spans.TermSpansWithId;
 
-/**	Enumeration of spans (e.g. element or relation spans) having some 
- * 	specific attribute(s) or <em>not</em> having some attribute(s).
+/**
+ * Enumeration of spans (e.g. element or relation spans) having some specific
+ * attribute(s) or <em>not</em> having some attribute(s). It is necessary that
+ * the spans have ids to be able to identify to which span an attribute belongs.
  * 
- * 	@author margaretha
+ * @author margaretha
  */
-public class SpanWithAttributeQuery extends SpanWithIdQuery{
-		
-	private boolean isMultipleAttributes;
-	private String type;
-	
-	public SpanWithAttributeQuery(SpanWithIdQuery firstClause,
-			SpanAttributeQuery secondClause, boolean collectPayloads) {
-		super(firstClause, secondClause, collectPayloads);
-		setType();
-	}
-	
-	public SpanWithAttributeQuery(SpanWithIdQuery firstClause,
-			List<SpanQuery> secondClauses, boolean collectPayloads) {
-		super(firstClause, secondClauses, collectPayloads);
-		isMultipleAttributes = true;
-		setType();
-	}	
-	
-	public String getType() {
-		return type;
-	}
+public class SpanWithAttributeQuery extends SpanWithIdQuery {
 
-	public void setType() {
-		if (SpanElementQuery.class.isInstance(firstClause)){
-			type = "spanElementWithAttribute"; 
-		}
-		else if (SpanRelationQuery.class.isInstance(firstClause)){
-			type = "spanRelationWithAttribute";	
-		}
-		else if (SpanTermWithIdQuery.class.isInstance(firstClause)){
-			type = "spanTermWithAttribute";	
-		}
-	}
+    private boolean isMultipleAttributes;
+    private String type;
 
-	@Override
-	public SimpleSpanQuery clone() {
-		SpanWithAttributeQuery sq;
-		if (!isMultipleAttributes){			
-			sq = new SpanWithAttributeQuery( 
-					(SpanWithIdQuery) firstClause.clone(), 
-					(SpanAttributeQuery) secondClause.clone(), 
-					collectPayloads);
-		}		
-		else {
-			List<SpanQuery> clauseList = new ArrayList<SpanQuery>();
-			SpanAttributeQuery saq;
-			for (SpanQuery q : this.clauseList ){
-				saq = (SpanAttributeQuery) q;
-				clauseList.add(saq.clone());
-			}
-			sq = new SpanWithAttributeQuery( 
-					(SpanWithIdQuery) firstClause.clone(), 
-					clauseList, 
-					collectPayloads);
-		}
-		return sq;
-	}
+    /**
+     * Constructs a SpanWithAttributeQuery for the specified SpanWithIdQuery and
+     * SpanAttributeQuery retrieving spans having a specific attribute.
+     * 
+     * @param firstClause a SpanWithIdQuery
+     * @param secondClause a SpanAttributeQuery
+     * @param collectPayloads a boolean flag representing the value
+     *        <code>true</code> if payloads are to be collected, otherwise
+     *        <code>false</code>.
+     */
+    public SpanWithAttributeQuery(SpanWithIdQuery firstClause,
+            SpanAttributeQuery secondClause, boolean collectPayloads) {
+        super(firstClause, secondClause, collectPayloads);
+        setType();
+    }
 
-	@Override
-	public Spans getSpans(AtomicReaderContext context, Bits acceptDocs,
-			Map<Term, TermContext> termContexts) throws IOException {
-		
-		Spans spans = this.getFirstClause().getSpans(context, acceptDocs, termContexts);
-		
-		if (type.equals("spanElementWithAttribute")){			
-			return new SpansWithAttribute(this, (ElementSpans) spans, 
-					context, acceptDocs, termContexts);
-		}
-		else if (type.equals("spanRelationWithAttribute")){
-			return new SpansWithAttribute(this, (RelationSpans) spans,
-					context, acceptDocs, termContexts);
-		}
-		
-		return new SpansWithAttribute(this, (TermSpansWithId) spans,
-				context, acceptDocs, termContexts);
-	}
+    /**
+     * @param firstClause a SpanWithIdQuery
+     * @param secondClauses a list of SpanAttributeQueries
+     * @param collectPayloads a boolean flag representing the value
+     *        <code>true</code> if payloads are to be collected, otherwise
+     *        <code>false</code>.
+     */
+    public SpanWithAttributeQuery(SpanWithIdQuery firstClause,
+            List<SpanQuery> secondClauses, boolean collectPayloads) {
+        super(firstClause, secondClauses, collectPayloads);
+        isMultipleAttributes = true;
+        setType();
+    }
 
-	@Override
-	public String toString(String field) {
-		
-		StringBuilder sb = new StringBuilder();
-		sb.append(type);
-		sb.append("(");
-		sb.append(firstClause.toString(field));
-		sb.append(", ");
-		if (isMultipleAttributes){
-			sb.append("[");
-			
-			SpanQuery sq;
-			for (int i=0; i < clauseList.size(); i++){
-				sq = clauseList.get(i); 
-				sb.append(sq.toString(field));
-				
-				if (i < clauseList.size() -1)
-					sb.append(", ");
-			}
-			
-			sb.append("]");
-		}
-		else {
-			sb.append(secondClause.toString(field));
-		}
-		sb.append(")");
-		return sb.toString();
-	}
+    /**
+     * Returns the type of the query.
+     * 
+     * @return the type of the query
+     */
+    public String getType() {
+        return type;
+    }
+
+    /** Sets the type of the query based of the class of the firstClause / first span.
+     * 
+     */
+    public void setType() {
+        if (SpanElementQuery.class.isInstance(firstClause)) {
+            type = "spanElementWithAttribute";
+        } else if (SpanRelationQuery.class.isInstance(firstClause)) {
+            type = "spanRelationWithAttribute";
+        } else if (SpanTermWithIdQuery.class.isInstance(firstClause)) {
+            type = "spanTermWithAttribute";
+        }
+    }
+
+    @Override
+    public SimpleSpanQuery clone() {
+        SpanWithAttributeQuery sq;
+        if (!isMultipleAttributes) {
+            sq = new SpanWithAttributeQuery(
+                    (SpanWithIdQuery) firstClause.clone(),
+                    (SpanAttributeQuery) secondClause.clone(), collectPayloads);
+        } else {
+            List<SpanQuery> clauseList = new ArrayList<SpanQuery>();
+            SpanAttributeQuery saq;
+            for (SpanQuery q : this.clauseList) {
+                saq = (SpanAttributeQuery) q;
+                clauseList.add(saq.clone());
+            }
+            sq = new SpanWithAttributeQuery(
+                    (SpanWithIdQuery) firstClause.clone(), clauseList,
+                    collectPayloads);
+        }
+        return sq;
+    }
+
+    @Override
+    public Spans getSpans(AtomicReaderContext context, Bits acceptDocs,
+            Map<Term, TermContext> termContexts) throws IOException {
+
+        Spans spans = this.getFirstClause().getSpans(context, acceptDocs,
+                termContexts);
+
+        if (type.equals("spanElementWithAttribute")) {
+            return new SpansWithAttribute(this, (ElementSpans) spans, context,
+                    acceptDocs, termContexts);
+        } else if (type.equals("spanRelationWithAttribute")) {
+            return new SpansWithAttribute(this, (RelationSpans) spans, context,
+                    acceptDocs, termContexts);
+        }
+
+        return new SpansWithAttribute(this, (TermSpansWithId) spans, context,
+                acceptDocs, termContexts);
+    }
+
+    @Override
+    public String toString(String field) {
+
+        StringBuilder sb = new StringBuilder();
+        sb.append(type);
+        sb.append("(");
+        sb.append(firstClause.toString(field));
+        sb.append(", ");
+        if (isMultipleAttributes) {
+            sb.append("[");
+
+            SpanQuery sq;
+            for (int i = 0; i < clauseList.size(); i++) {
+                sq = clauseList.get(i);
+                sb.append(sq.toString(field));
+
+                if (i < clauseList.size() - 1)
+                    sb.append(", ");
+            }
+
+            sb.append("]");
+        } else {
+            sb.append(secondClause.toString(field));
+        }
+        sb.append(")");
+        return sb.toString();
+    }
 }
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanWithIdQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanWithIdQuery.java
index aefd7ce..55e2744 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanWithIdQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanWithIdQuery.java
@@ -4,19 +4,56 @@
 
 import org.apache.lucene.search.spans.SpanQuery;
 
-public abstract class SpanWithIdQuery extends SimpleSpanQuery{
+/**
+ * Base query for span queries whose resulting spans requires an id, for
+ * instance {@link SpanElementQuery} and {@link SpanRelationQuery}.
+ * 
+ * @author margaretha
+ * 
+ */
+public abstract class SpanWithIdQuery extends SimpleSpanQuery {
 
-	public SpanWithIdQuery(SpanQuery firstClause, boolean collectPayloads) {
-		super(firstClause, collectPayloads);
-	}
-	
-	public SpanWithIdQuery(SpanQuery firstClause, SpanQuery secondClause,
-			boolean collectPayloads) {
-		super(firstClause, secondClause, collectPayloads);
-	}
-	
-	public SpanWithIdQuery(SpanQuery firstClause,
-			List<SpanQuery> secondClauses, boolean collectPayloads) {
-		super(firstClause, secondClauses, collectPayloads);
-	}
+    /**
+     * Constructs SpanWithIdQuery based on the given {@link SpanQuery} and the
+     * collectPayloads flag, for example, {@link SpanElementQuery}.
+     * 
+     * @param firstClause a SpanQuery
+     * @param collectPayloads a boolean flag representing the value
+     *        <code>true</code> if payloads are to be collected, otherwise
+     *        <code>false</code>.
+     */
+    public SpanWithIdQuery(SpanQuery firstClause, boolean collectPayloads) {
+        super(firstClause, collectPayloads);
+    }
+
+    /**
+     * Constructs SpanWithIdQuery based on two span queries and the
+     * collectPayloads flag, for instance, query a relation having a specific
+     * attribute.
+     * 
+     * @param firstClause a SpanQuery
+     * @param secondClause a SpanQuery
+     * @param collectPayloads a boolean flag representing the value
+     *        <code>true</code> if payloads are to be collected, otherwise
+     *        <code>false</code>.
+     */
+    public SpanWithIdQuery(SpanQuery firstClause, SpanQuery secondClause,
+            boolean collectPayloads) {
+        super(firstClause, secondClause, collectPayloads);
+    }
+
+    /**
+     * Constructs SpanWithIdQuery based on a span query and a list of span
+     * queries, for instance, query an element having two specific attributes.
+     * 
+     * @param firstClause a SpanQuery
+     * @param secondClauses a list of SpanQuery
+     * @param collectPayloads a boolean flag representing the value
+     *        <code>true</code> if payloads are to be collected, otherwise
+     *        <code>false</code>.
+     */
+    public SpanWithIdQuery(SpanQuery firstClause,
+            List<SpanQuery> secondClauses, boolean collectPayloads) {
+        super(firstClause, secondClauses, collectPayloads);
+    }
 }
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/ElementSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/ElementSpans.java
index 8b8d90b..f01bd1f 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/ElementSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/ElementSpans.java
@@ -14,161 +14,182 @@
 import org.apache.lucene.search.spans.Spans;
 import org.apache.lucene.search.spans.TermSpans;
 import org.apache.lucene.util.Bits;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import de.ids_mannheim.korap.query.SpanElementQuery;
 
-/**  
- * @author Nils Diewald, margaretha
- *
- * Use copyFrom instead of clone
+/**
+ * Enumeration of spans which are elements such as phrases, sentences and
+ * paragraphs.
+ * 
+ * @author margaretha
+ * @author Nils Diewald
  */
 public class ElementSpans extends SpansWithId {
 
-	private List<CandidateElementSpans> candidateList;
-	private int currentDoc, currentPosition;
-	private TermSpans termSpans;	
-	
-	private Logger logger = LoggerFactory.getLogger(ElementSpans.class);
+    private List<CandidateElementSpan> candidateList;
+    private int currentDoc, currentPosition;
+    private TermSpans termSpans;
 
-	public ElementSpans(SpanElementQuery spanElementQuery,
-			AtomicReaderContext context, Bits acceptDocs,
-			Map<Term, TermContext> termContexts) throws IOException {
-		super(spanElementQuery, context, acceptDocs, termContexts);
-		candidateList = new ArrayList<>();
-		termSpans = (TermSpans) firstSpans;
-		hasMoreSpans = termSpans.next();
-		if (hasMoreSpans) {
-			currentDoc = termSpans.doc();
-			currentPosition = termSpans.start();
-		}
-	}
+    /**
+     * Constructs ElementSpans for the given {@link SpanElementQuery}.
+     * 
+     * @param spanElementQuery a SpanElementQuery
+     * @param context
+     * @param acceptDocs
+     * @param termContexts
+     * @throws IOException
+     */
+    public ElementSpans(SpanElementQuery spanElementQuery,
+            AtomicReaderContext context, Bits acceptDocs,
+            Map<Term, TermContext> termContexts) throws IOException {
+        super(spanElementQuery, context, acceptDocs, termContexts);
+        candidateList = new ArrayList<>();
+        termSpans = (TermSpans) firstSpans;
+        hasMoreSpans = termSpans.next();
+        if (hasMoreSpans) {
+            currentDoc = termSpans.doc();
+            currentPosition = termSpans.start();
+        }
+    }
 
-	@Override
-	public boolean next() throws IOException {
-		isStartEnumeration=false;
-		return advance();
-	}
-	
-	/**	Get the next match by first checking the candidate match list
-	 * 	and setting the list when it is empty.
-	 * */
-	private boolean advance() throws IOException {
-		while(hasMoreSpans || !candidateList.isEmpty()){
-			if (!candidateList.isEmpty()){
-				CandidateElementSpans cs = candidateList.get(0);
-				this.matchDocNumber = cs.getDoc();
-				this.matchStartPosition = cs.getStart();
-				this.matchEndPosition = cs.getEnd();
-				this.matchPayload = cs.getPayloads();				
-				//this.setElementRef(cs.getSpanId());				
-				this.setSpanId(cs.getSpanId());
-				candidateList.remove(0);
-				return true;
-			}
-			else{
-			    //logger.info("Setting candidate list");
-				setCandidateList();				
-				currentDoc = termSpans.doc();
-				currentPosition = termSpans.start();
-			}
-		}
-		return false;
-	}
+    @Override
+    public boolean next() throws IOException {
+        isStartEnumeration = false;
+        return advance();
+    }
 
-	/**	Collect all the elements in the same start position and sort them by
-	 * 	end position (smallest first).
-	 * */
-	private void setCandidateList() throws IOException {
-		while (hasMoreSpans &&	termSpans.doc() == currentDoc && 
-				termSpans.start() == currentPosition){
-			CandidateElementSpans cs = new CandidateElementSpans(termSpans,
-					spanId);
-					//elementRef);
-			readPayload(cs);
-			candidateList.add(cs);
-			hasMoreSpans = termSpans.next();
-		}
-		Collections.sort(candidateList);
-	}
-	
-	
-	/**	This method reads the payload of the termSpan and assigns the end 
-	 * 	position and element ref to the candidate match. The character offset
-	 *  payload is set as the candidate match payload.
-	 *  <br/><br/>
-	 * 	<em>Note</em>: payloadbuffer should actually collects all other payload
-	 * 	beside end position and element ref, but KorapIndex identify element's 
-	 * 	payload by its length (8), which is only the character offsets. So
-	 * 	these offsets are directly set as the candidate match payload.	
-	 * 
-	 * 	@author margaretha
-	 * */
-	private void readPayload(CandidateElementSpans cs) throws IOException {   	
-		List<byte[]> payload = (List<byte[]>) termSpans.getPayload();
-		int length = payload.get(0).length;
-		ByteBuffer bb = ByteBuffer.allocate(length);
-		bb.put(payload.get(0));
-		
-	    if (!payload.isEmpty()) {
-			// set element end position from payload
-			cs.setEnd(bb.getInt(8));
-			
-			if (hasSpanId){ // copy element id
-				cs.setSpanId(bb.getShort(12));
-			}
-			else{ // set element id -1
-				cs.setSpanId((short) -1);
-			}
-			// Copy the start and end character offsets
-			byte[] b = new byte[8];			
-			b = Arrays.copyOfRange(bb.array(), 0, 8);
-			cs.setPayloads(Collections.singletonList(b));
-	    }
-	    else {	
-			cs.setEnd(cs.getStart());
-			cs.setSpanId((short) -1);
-			cs.setPayloads(null);
-    	}
-	}
-	
-	@Override
-	public boolean skipTo(int target) throws IOException {
-		if (hasMoreSpans && (firstSpans.doc() < target)){
-  			if (!firstSpans.skipTo(target)){
-  				candidateList.clear();
-  				return false;
-  			}
-  		}		
-		setCandidateList();
-		matchPayload.clear();
-		isStartEnumeration=false;
-		return advance();
-	}
+    /**
+     * Advances the ElementSpans to the next match by first checking the
+     * candidate match list. If the list is empty, it will be set/filled in
+     * first. Tells if there is a next match or not.
+     * 
+     * @return <code>true</code> if a match is found, <code>false</code>
+     *         otherwise.
+     * @throws IOException
+     */
+    private boolean advance() throws IOException {
+        while (hasMoreSpans || !candidateList.isEmpty()) {
+            if (!candidateList.isEmpty()) {
+                CandidateElementSpan cs = candidateList.get(0);
+                this.matchDocNumber = cs.getDoc();
+                this.matchStartPosition = cs.getStart();
+                this.matchEndPosition = cs.getEnd();
+                this.matchPayload = cs.getPayloads();
+                // this.setElementRef(cs.getSpanId());
+                this.setSpanId(cs.getSpanId());
+                candidateList.remove(0);
+                return true;
+            } else {
+                // logger.info("Setting candidate list");
+                setCandidateList();
+                currentDoc = termSpans.doc();
+                currentPosition = termSpans.start();
+            }
+        }
+        return false;
+    }
 
-	@Override
-	public long cost() {
-		return termSpans.cost();
-	}
-	
-	/** Match candidate for element spans.
-	 * */	
-	class CandidateElementSpans extends CandidateSpan {
-		
-		private short elementRef;
-		
-		public CandidateElementSpans(Spans span, short elementRef) 
-				throws IOException {
-			super(span);
-			setSpanId(elementRef);
-		}
-		
-		public void setSpanId(short elementRef) {
-			this.elementRef = elementRef;
-		}
-		public short getSpanId() {
-			return elementRef;
-		}	
-	}
+    /**
+     * Collects all the elements starting at the same position and sort them by
+     * their end positions. The list starts with the element having the smallest
+     * end position.
+     * 
+     * @throws IOException
+     */
+    private void setCandidateList() throws IOException {
+        while (hasMoreSpans && termSpans.doc() == currentDoc
+                && termSpans.start() == currentPosition) {
+            CandidateElementSpan cs = new CandidateElementSpan(termSpans,
+                    spanId);
+            // elementRef);
+            readPayload(cs);
+            candidateList.add(cs);
+            hasMoreSpans = termSpans.next();
+        }
+        Collections.sort(candidateList);
+    }
+
+    /**
+     * Reads the payloads of the termSpan and sets the end position and element
+     * id from the payloads for the candidate match. The payloads for
+     * character-offsets are set as the candidate match payloads. <br/>
+     * <br/>
+     * <em>Note</em>: payloadbuffer should actually collects all other payload
+     * beside end position and element id, but KorapIndex identify element's
+     * payloads by its length (8), which represents the character offset
+     * payloads. So these offsets are directly set as the candidate match
+     * payload.
+     * 
+     * @param cs a candidate match
+     * @throws IOException
+     */
+    private void readPayload(CandidateElementSpan cs) throws IOException {
+        List<byte[]> payload = (List<byte[]>) termSpans.getPayload();
+        int length = payload.get(0).length;
+        ByteBuffer bb = ByteBuffer.allocate(length);
+        bb.put(payload.get(0));
+
+        if (!payload.isEmpty()) {
+            // set element end position from payload
+            cs.setEnd(bb.getInt(8));
+
+            if (hasSpanId) { // copy element id
+                cs.setSpanId(bb.getShort(12));
+            } else { // set element id -1
+                cs.setSpanId((short) -1);
+            }
+            // Copy the start and end character offsets
+            byte[] b = new byte[8];
+            b = Arrays.copyOfRange(bb.array(), 0, 8);
+            cs.setPayloads(Collections.singletonList(b));
+        } else {
+            cs.setEnd(cs.getStart());
+            cs.setSpanId((short) -1);
+            cs.setPayloads(null);
+        }
+    }
+
+    @Override
+    public boolean skipTo(int target) throws IOException {
+        if (hasMoreSpans && (firstSpans.doc() < target)) {
+            if (!firstSpans.skipTo(target)) {
+                candidateList.clear();
+                return false;
+            }
+        }
+        setCandidateList();
+        matchPayload.clear();
+        isStartEnumeration = false;
+        return advance();
+    }
+
+    @Override
+    public long cost() {
+        return termSpans.cost();
+    }
+
+    /**
+     * Match candidate for element spans.
+     * 
+     * @author margaretha
+     * 
+     */
+    class CandidateElementSpan extends CandidateSpan {
+
+        private short elementId;
+
+        public CandidateElementSpan(Spans span, short elementId)
+                throws IOException {
+            super(span);
+            setSpanId(elementId);
+        }
+
+        public void setSpanId(short elementId) {
+            this.elementId = elementId;
+        }
+
+        public short getSpanId() {
+            return elementId;
+        }
+    }
 };
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/SpansWithId.java b/src/main/java/de/ids_mannheim/korap/query/spans/SpansWithId.java
index f1d836a..de4b8e6 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/SpansWithId.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/SpansWithId.java
@@ -10,25 +10,47 @@
 
 import de.ids_mannheim.korap.query.SpanWithIdQuery;
 
-/** Base class for span enumeration with spanid property.
- * 	@author margaretha
+/**
+ * Base class for enumeration of span requiring an id, such as elements and
+ * relations.
+ * 
+ * @author margaretha
  * */
-public abstract class SpansWithId extends SimpleSpans{
+public abstract class SpansWithId extends SimpleSpans {
 
-	protected short spanId;
-	protected boolean hasSpanId = false; // A dummy flag
-	
-	public SpansWithId(SpanWithIdQuery spanWithIdQuery,
-			AtomicReaderContext context, Bits acceptDocs,
-			Map<Term, TermContext> termContexts) throws IOException {
-		super(spanWithIdQuery, context, acceptDocs, termContexts);
-	}
+    protected short spanId;
+    protected boolean hasSpanId = false; // A dummy flag
 
-	public short getSpanId() {
-		return spanId;
-	}
+    /**
+     * Constructs SpansWithId for the given {@link SpanWithIdQuery}.
+     * 
+     * @param spanWithIdQuery a SpanWithIdQuery
+     * @param context
+     * @param acceptDocs
+     * @param termContexts
+     * @throws IOException
+     */
+    public SpansWithId(SpanWithIdQuery spanWithIdQuery,
+            AtomicReaderContext context, Bits acceptDocs,
+            Map<Term, TermContext> termContexts) throws IOException {
+        super(spanWithIdQuery, context, acceptDocs, termContexts);
+    }
 
-	public void setSpanId(short spanId) {
-		this.spanId = spanId;
-	}
+    /**
+     * Returns the span id of the current span
+     * 
+     * @return the span id of the current span
+     */
+    public short getSpanId() {
+        return spanId;
+    }
+
+    /**
+     * Sets the span id of the current span
+     * 
+     * @param spanId span id
+     */
+    public void setSpanId(short spanId) {
+        this.spanId = spanId;
+    }
 }