Added comments.

Change-Id: Id0285a80574481c65812589263f4a001bb92d40a
diff --git a/src/main/java/de/ids_mannheim/korap/query/object/KoralBoundary.java b/src/main/java/de/ids_mannheim/korap/query/object/KoralBoundary.java
index 0faee0e..c28cece 100644
--- a/src/main/java/de/ids_mannheim/korap/query/object/KoralBoundary.java
+++ b/src/main/java/de/ids_mannheim/korap/query/object/KoralBoundary.java
@@ -3,6 +3,11 @@
 import java.util.LinkedHashMap;
 import java.util.Map;
 
+/** Definition of koral:boundary in KoralQuery.
+ * 
+ * @author margaretha
+ *
+ */
 public class KoralBoundary implements KoralObject {
 
     private static final KoralType type = KoralType.BOUNDARY;
diff --git a/src/main/java/de/ids_mannheim/korap/query/object/KoralContext.java b/src/main/java/de/ids_mannheim/korap/query/object/KoralContext.java
index abdde0b..56f00a1 100644
--- a/src/main/java/de/ids_mannheim/korap/query/object/KoralContext.java
+++ b/src/main/java/de/ids_mannheim/korap/query/object/KoralContext.java
@@ -1,6 +1,9 @@
 package de.ids_mannheim.korap.query.object;
 
-/**
+/** Context definition for the search scope in WithinQuery,
+ * for instance, a withinquery in poliqarp is
+ * <code>"Bild" within s</code>.
+ * 
  * @author margaretha
  * 
  */
diff --git a/src/main/java/de/ids_mannheim/korap/query/object/KoralDistance.java b/src/main/java/de/ids_mannheim/korap/query/object/KoralDistance.java
index eb88f58..57e1b9a 100644
--- a/src/main/java/de/ids_mannheim/korap/query/object/KoralDistance.java
+++ b/src/main/java/de/ids_mannheim/korap/query/object/KoralDistance.java
@@ -3,6 +3,11 @@
 import java.util.LinkedHashMap;
 import java.util.Map;
 
+/** Definition of koral:distance in KoralQuery.
+ *  
+ * @author margaretha
+ *
+ */
 public class KoralDistance implements KoralObject {
 
     private final KoralType type = KoralType.DISTANCE;
diff --git a/src/main/java/de/ids_mannheim/korap/query/object/KoralGroup.java b/src/main/java/de/ids_mannheim/korap/query/object/KoralGroup.java
index b304f72..87d98e8 100644
--- a/src/main/java/de/ids_mannheim/korap/query/object/KoralGroup.java
+++ b/src/main/java/de/ids_mannheim/korap/query/object/KoralGroup.java
@@ -10,7 +10,7 @@
 import de.ids_mannheim.korap.query.object.KoralOperation;
 import de.ids_mannheim.korap.query.object.KoralType;
 
-/**
+/** Definition of koral:group in KoralQuery.
  * @author margaretha
  * 
  */
@@ -25,7 +25,13 @@
     private List<KoralDistance> distances;
     private List<Frame> frames;
     private KoralBoundary boundary;
-
+    
+//    private int[] classIn;
+//    private int classOut;
+//    private int classRefCheck;
+//    private int classRefOp;
+//    private boolean exclude = false;
+    
     public KoralGroup (KoralOperation operation) {
         this.operation = operation;
     }
@@ -94,7 +100,7 @@
         }
 
         List<Map<String, Object>> operandList = new ArrayList<Map<String, Object>>();
-        for (Object o : operands) {
+        for (KoralObject o : operands) {
             operandList.add(MapBuilder.buildQueryMap(o));
         }
         map.put("operands", operandList);
diff --git a/src/main/java/de/ids_mannheim/korap/query/object/KoralMatchOperator.java b/src/main/java/de/ids_mannheim/korap/query/object/KoralMatchOperator.java
index bd5f6ea..2d8997b 100644
--- a/src/main/java/de/ids_mannheim/korap/query/object/KoralMatchOperator.java
+++ b/src/main/java/de/ids_mannheim/korap/query/object/KoralMatchOperator.java
@@ -1,6 +1,6 @@
 package de.ids_mannheim.korap.query.object;
 
-/**
+/** Definition of the match operations used within koral:term.
  * @author margaretha
  * 
  */
diff --git a/src/main/java/de/ids_mannheim/korap/query/object/KoralObject.java b/src/main/java/de/ids_mannheim/korap/query/object/KoralObject.java
index 21fcf67..2fd4563 100644
--- a/src/main/java/de/ids_mannheim/korap/query/object/KoralObject.java
+++ b/src/main/java/de/ids_mannheim/korap/query/object/KoralObject.java
@@ -8,5 +8,9 @@
  */
 public interface KoralObject {
 
+    /** Serializes the KoralObject into JSON-LD and structures it as a map.  
+     * 
+     * @return a map containing parts of the JSON-LD serialization of the Koral object.
+     */
     public Map<String, Object> buildMap();
 }
diff --git a/src/main/java/de/ids_mannheim/korap/query/object/KoralOperation.java b/src/main/java/de/ids_mannheim/korap/query/object/KoralOperation.java
index 972bfd3..d81557f 100644
--- a/src/main/java/de/ids_mannheim/korap/query/object/KoralOperation.java
+++ b/src/main/java/de/ids_mannheim/korap/query/object/KoralOperation.java
@@ -1,6 +1,6 @@
 package de.ids_mannheim.korap.query.object;
 
-/**
+/** Definition of possible operations within koral:group. 
  * @author margaretha
  * 
  */
diff --git a/src/main/java/de/ids_mannheim/korap/query/object/KoralSpan.java b/src/main/java/de/ids_mannheim/korap/query/object/KoralSpan.java
index 4310bb9..aa299ab 100644
--- a/src/main/java/de/ids_mannheim/korap/query/object/KoralSpan.java
+++ b/src/main/java/de/ids_mannheim/korap/query/object/KoralSpan.java
@@ -6,7 +6,8 @@
 import de.ids_mannheim.korap.query.serialize.util.KoralException;
 import de.ids_mannheim.korap.query.serialize.util.StatusCodes;
 
-/**
+/** Definition of koral:span in KoralQuery.
+ * 
  * @author margaretha
  *
  */
diff --git a/src/main/java/de/ids_mannheim/korap/query/object/KoralTerm.java b/src/main/java/de/ids_mannheim/korap/query/object/KoralTerm.java
index f9f60cd..9409ab7 100644
--- a/src/main/java/de/ids_mannheim/korap/query/object/KoralTerm.java
+++ b/src/main/java/de/ids_mannheim/korap/query/object/KoralTerm.java
@@ -8,7 +8,8 @@
 import de.ids_mannheim.korap.query.object.KoralMatchOperator;
 import de.ids_mannheim.korap.query.object.KoralType;
 
-/**
+/** Definition of koral:term in KoralQuery.
+ * 
  * @author margaretha
  * 
  */
@@ -25,6 +26,7 @@
     private KoralTermType type;
     
     private boolean caseSensitive = true;
+    private boolean diacriticSensitive = true; 
 
     public KoralTerm(String key) throws KoralException {
     	if (key == null){
@@ -96,6 +98,14 @@
         this.caseSensitive = isCaseSensitive;
     }
 
+    public boolean isDiacriticSensitive() {
+        return diacriticSensitive;
+    }
+
+    public void setDiacriticSensitive(boolean diacriticSensitive) {
+        this.diacriticSensitive = diacriticSensitive;
+    }
+
     @Override
     public Map<String, Object> buildMap() {
         Map<String, Object> map = new LinkedHashMap<String, Object>();
@@ -103,13 +113,20 @@
         if (!isCaseSensitive()) {
             map.put("caseInsensitive", "true");
         }
-        
+        if (!isDiacriticSensitive()){
+            map.put("diacriticInsensitive", "true");
+        }
+            
         map.put("key", getKey());
         if (value != null){
         	map.put("value", getValue());
         }
-        map.put("foundry", getFoundry());
-        map.put("layer", getLayer());
+        if (foundry != null){
+           map.put("foundry", getFoundry());
+        }
+        if (layer !=null){
+           map.put("layer", getLayer());
+        }
         if (type != null){
         	map.put("type", getType().toString());
         }
@@ -119,6 +136,11 @@
         return map;
     }
 
+    /** Definition of possible types of koral:term.
+     * 
+     * @author margaretha
+     *
+     */
     public enum KoralTermType {
         STRING("type:string"), REGEX("type:regex"), WILDCARD("type:wildcard"), PUNCT(
                 "type:punct");
diff --git a/src/main/java/de/ids_mannheim/korap/query/object/KoralTermGroup.java b/src/main/java/de/ids_mannheim/korap/query/object/KoralTermGroup.java
index eaae803..c4b1b63 100644
--- a/src/main/java/de/ids_mannheim/korap/query/object/KoralTermGroup.java
+++ b/src/main/java/de/ids_mannheim/korap/query/object/KoralTermGroup.java
@@ -8,7 +8,8 @@
 import de.ids_mannheim.korap.query.serialize.MapBuilder;
 import de.ids_mannheim.korap.query.serialize.util.KoralException;
 
-/**
+/** Definition of koral:termGroup in KoralQuery.
+ * 
  * @author margaretha
  * 
  */
@@ -19,7 +20,7 @@
     private String relation;
     private List<KoralObject> operands = new ArrayList<KoralObject>();
 
-    public KoralTermGroup (KoralRelation relation, List<KoralObject> operands)
+    public KoralTermGroup (KoralTermGroupRelation relation, List<KoralObject> operands)
             throws KoralException {
         this.relation = relation.toString();
         this.operands = operands;
@@ -48,7 +49,7 @@
         map.put("relation", getRelation());
 
         List<Map<String, Object>> operandList = new ArrayList<Map<String, Object>>();
-        for (Object o : getOperands()) {
+        for (KoralObject o : getOperands()) {
             operandList.add(MapBuilder.buildQueryMap(o));
         }
         map.put("operands", operandList);
diff --git a/src/main/java/de/ids_mannheim/korap/query/object/KoralTermGroupRelation.java b/src/main/java/de/ids_mannheim/korap/query/object/KoralTermGroupRelation.java
index 84a1ff8..3c7707e 100644
--- a/src/main/java/de/ids_mannheim/korap/query/object/KoralTermGroupRelation.java
+++ b/src/main/java/de/ids_mannheim/korap/query/object/KoralTermGroupRelation.java
@@ -1,10 +1,11 @@
 package de.ids_mannheim.korap.query.object;
 
-/**
+/** Definition of the relations used within koral:termGroup.
+ * 
  * @author margaretha
  * 
  */
-public enum KoralRelation {
+public enum KoralTermGroupRelation {
 
     AND, OR;
 
diff --git a/src/main/java/de/ids_mannheim/korap/query/object/KoralToken.java b/src/main/java/de/ids_mannheim/korap/query/object/KoralToken.java
index 7798566..431b3ea 100644
--- a/src/main/java/de/ids_mannheim/korap/query/object/KoralToken.java
+++ b/src/main/java/de/ids_mannheim/korap/query/object/KoralToken.java
@@ -6,7 +6,8 @@
 import de.ids_mannheim.korap.query.object.KoralObject;
 import de.ids_mannheim.korap.query.object.KoralType;
 
-/**
+/** Definition of koral:token in KoralQuery.
+ * 
  * @author margaretha
  * 
  */
diff --git a/src/main/java/de/ids_mannheim/korap/query/object/KoralType.java b/src/main/java/de/ids_mannheim/korap/query/object/KoralType.java
index df7608f..4992f43 100644
--- a/src/main/java/de/ids_mannheim/korap/query/object/KoralType.java
+++ b/src/main/java/de/ids_mannheim/korap/query/object/KoralType.java
@@ -1,6 +1,7 @@
 package de.ids_mannheim.korap.query.object;
 
-/**
+/** Definition of various types of KoralQuery building objects.
+ *  
  * @author margaretha
  * 
  */
diff --git a/src/main/java/de/ids_mannheim/korap/query/parse/fcsql/ExpressionParser.java b/src/main/java/de/ids_mannheim/korap/query/parse/fcsql/ExpressionParser.java
index 42f5f83..1fd9f6e 100644
--- a/src/main/java/de/ids_mannheim/korap/query/parse/fcsql/ExpressionParser.java
+++ b/src/main/java/de/ids_mannheim/korap/query/parse/fcsql/ExpressionParser.java
@@ -8,7 +8,7 @@
 
 import de.ids_mannheim.korap.query.object.KoralMatchOperator;
 import de.ids_mannheim.korap.query.object.KoralObject;
-import de.ids_mannheim.korap.query.object.KoralRelation;
+import de.ids_mannheim.korap.query.object.KoralTermGroupRelation;
 import de.ids_mannheim.korap.query.object.KoralTerm;
 import de.ids_mannheim.korap.query.object.KoralTerm.KoralTermType;
 import de.ids_mannheim.korap.query.object.KoralTermGroup;
@@ -26,6 +26,9 @@
 import eu.clarin.sru.server.fcs.parser.RegexFlag;
 
 /**
+ * This class handles and parses various FCSQL expressions (e.g.
+ * simple and boolean expressions) into a KoralObject.
+ * 
  * @author margaretha
  * 
  */
@@ -41,10 +44,34 @@
             .asList(new String[] { FOUNDRY_CNX, FOUNDRY_OPENNLP, FOUNDRY_TT,
                     FOUNDRY_MATE, FOUNDRY_XIP });
 
-    public KoralObject parseExpression(QueryNode queryNode) throws KoralException {
+    /**
+     * Parses the given query node and constructs a koral object
+     * representation of it.
+     * 
+     * @param queryNode
+     *            an FCSQL query node
+     * @return a koral object representation of the given node
+     * @throws KoralException
+     */
+    public KoralObject parseExpression(QueryNode queryNode)
+            throws KoralException {
         return parseExpression(queryNode, false, true);
     }
 
+    /**
+     * Parses the given query node using the specified parameters.
+     * 
+     * @param queryNode
+     *            an FCSQL query node
+     * @param isNot
+     *            a boolean value indicating if the query node was
+     *            negated or not.
+     * @param isToken
+     *            a boolean value indicating if the query node is a
+     *            token or not.
+     * @return a koral object representation of the given node
+     * @throws KoralException
+     */
     public KoralObject parseExpression(QueryNode queryNode, boolean isNot,
             boolean isToken) throws KoralException {
 
@@ -54,10 +81,12 @@
         else if (queryNode instanceof ExpressionAnd) {
             List<QueryNode> operands = queryNode.getChildren();
             if (isNot) {
-                return parseBooleanExpression(operands, KoralRelation.OR);
+                return parseBooleanExpression(operands,
+                        KoralTermGroupRelation.OR);
             }
             else {
-                return parseBooleanExpression(operands, KoralRelation.AND);
+                return parseBooleanExpression(operands,
+                        KoralTermGroupRelation.AND);
             }
         }
         else if (queryNode instanceof ExpressionGroup) {
@@ -71,10 +100,12 @@
         else if (queryNode instanceof ExpressionOr) {
             List<QueryNode> operands = queryNode.getChildren();
             if (isNot) {
-                return parseBooleanExpression(operands, KoralRelation.AND);
+                return parseBooleanExpression(operands,
+                        KoralTermGroupRelation.AND);
             }
             else {
-                return parseBooleanExpression(operands, KoralRelation.OR);
+                return parseBooleanExpression(operands,
+                        KoralTermGroupRelation.OR);
             }
         }
         else if (queryNode instanceof ExpressionWildcard) {
@@ -86,8 +117,20 @@
         }
     }
 
+    /**
+     * Handles a boolean expression by parsing the given operands and
+     * creates a koral token using the parsed operands and the given
+     * relation.
+     * 
+     * @param operands
+     *            a list of query node
+     * @param relation
+     *            the boolean operator
+     * @return a koral token
+     * @throws KoralException
+     */
     private KoralToken parseBooleanExpression(List<QueryNode> operands,
-            KoralRelation relation) throws KoralException {
+            KoralTermGroupRelation relation) throws KoralException {
         List<KoralObject> terms = new ArrayList<>();
         for (QueryNode node : operands) {
             terms.add(parseExpression(node, false, false));
@@ -96,8 +139,23 @@
         return new KoralToken(termGroup);
     }
 
-    private KoralObject parseSimpleExpression(Expression expression, boolean isNot,
-            boolean isToken) throws KoralException {
+    /**
+     * Parses the given simple expression considering the other
+     * specified parameters.
+     * 
+     * @param expression
+     *            a simple expression
+     * @param isNot
+     *            a boolean value indicating if the expression was
+     *            negated or not.
+     * @param isToken
+     *            a boolean value indicating if the expression is a
+     *            token or not.
+     * @return
+     * @throws KoralException
+     */
+    private KoralObject parseSimpleExpression(Expression expression,
+            boolean isNot, boolean isToken) throws KoralException {
         KoralTerm koralTerm = parseTerm(expression, isNot);
         if (isToken) {
             return new KoralToken(koralTerm);
@@ -107,9 +165,21 @@
         }
     }
 
-    public KoralTerm parseTerm(Expression expression, boolean isNot) throws KoralException {
-    	KoralTerm koralTerm = null;
-    	koralTerm = new KoralTerm(expression.getRegexValue());
+    /**
+     * Parses the given expression and constructs a KoralTerm.
+     * 
+     * @param expression
+     *            an expression
+     * @param isNot
+     *            a boolean value indicating if the expression was
+     *            negated or not.
+     * @return a koral term
+     * @throws KoralException
+     */
+    public KoralTerm parseTerm(Expression expression, boolean isNot)
+            throws KoralException {
+        KoralTerm koralTerm = null;
+        koralTerm = new KoralTerm(expression.getRegexValue());
         koralTerm.setType(KoralTermType.REGEX);
         parseLayerIdentifier(koralTerm, expression.getLayerIdentifier());
         parseQualifier(koralTerm, expression.getLayerQualifier());
@@ -118,7 +188,18 @@
         return koralTerm;
     }
 
-    private void parseLayerIdentifier(KoralTerm koralTerm, String identifier) throws KoralException {
+    /**
+     * Parses the given layer identifier and adds it to the koral
+     * term.
+     * 
+     * @param koralTerm
+     *            a koral term
+     * @param identifier
+     *            a layer identifier
+     * @throws KoralException
+     */
+    private void parseLayerIdentifier(KoralTerm koralTerm, String identifier)
+            throws KoralException {
         String layer = null;
         if (identifier == null) {
             throw new KoralException(StatusCodes.MALFORMED_QUERY,
@@ -142,7 +223,17 @@
         koralTerm.setLayer(layer);
     }
 
-    private void parseQualifier(KoralTerm koralTerm, String qualifier) throws KoralException {
+    /**
+     * Parses the given layer qualifier and adds it to the koral term.
+     * 
+     * @param koralTerm
+     *            a koral term
+     * @param qualifier
+     *            a layer qualifier
+     * @throws KoralException
+     */
+    private void parseQualifier(KoralTerm koralTerm, String qualifier)
+            throws KoralException {
         String layer = koralTerm.getLayer();
         if (layer == null) {
             return;
@@ -158,7 +249,7 @@
         }
         else if (qualifier.equals(FOUNDRY_OPENNLP) && layer.equals("l")) {
             throw new KoralException(StatusCodes.UNKNOWN_QUERY_ELEMENT,
-                            "SRU diagnostic 48: Layer lemma with qualifier opennlp is unsupported.");
+                    "SRU diagnostic 48: Layer lemma with qualifier opennlp is unsupported.");
         }
         else if (!supportedFoundries.contains(qualifier)) {
             throw new KoralException(StatusCodes.UNKNOWN_QUERY_ELEMENT,
@@ -169,27 +260,51 @@
         koralTerm.setFoundry(qualifier);
     }
 
+    /**
+     * Parses the given match operator and adds it to the koral term.
+     * 
+     * @param koralTerm
+     *            a koral term
+     * @param operator
+     *            a match operator
+     * @param isNot
+     *            a boolean value indicating if there was a negation
+     *            or not.
+     * @throws KoralException
+     */
     private void parseOperator(KoralTerm koralTerm, Operator operator,
             boolean isNot) throws KoralException {
-    	KoralMatchOperator matchOperator = null;
+        KoralMatchOperator matchOperator = null;
         if (operator == null || operator == Operator.EQUALS) {
-            matchOperator = isNot ? KoralMatchOperator.NOT_EQUALS : KoralMatchOperator.EQUALS;
+            matchOperator = isNot ? KoralMatchOperator.NOT_EQUALS
+                    : KoralMatchOperator.EQUALS;
         }
         else if (operator == Operator.NOT_EQUALS) {
-            matchOperator = isNot ? KoralMatchOperator.EQUALS : KoralMatchOperator.NOT_EQUALS;
+            matchOperator = isNot ? KoralMatchOperator.EQUALS
+                    : KoralMatchOperator.NOT_EQUALS;
         }
         else {
-        	throw new KoralException(StatusCodes.UNKNOWN_QUERY_ELEMENT,
-                            "SRU diagnostic 37:" + operator.name()
-                                    + " is unsupported.");
+            throw new KoralException(StatusCodes.UNKNOWN_QUERY_ELEMENT,
+                    "SRU diagnostic 37:" + operator.name() + " is unsupported.");
         }
         koralTerm.setOperator(matchOperator);
     }
 
-    private void parseRegexFlags(KoralTerm koralTerm, Set<RegexFlag> set) throws KoralException {
+    /**
+     * Parses the given set of regex flags and adds them to the koral
+     * term.
+     * 
+     * @param koralTerm
+     *            a koral term
+     * @param set
+     *            a set of regex flags
+     * @throws KoralException
+     */
+    private void parseRegexFlags(KoralTerm koralTerm, Set<RegexFlag> set)
+            throws KoralException {
         // default case sensitive
         if (set == null) return;
-        
+
         ArrayList<String> names = new ArrayList<String>();
         Iterator<RegexFlag> i = set.iterator();
         while (i.hasNext()) {
diff --git a/src/main/java/de/ids_mannheim/korap/query/parse/fcsql/FCSSRUQueryParser.java b/src/main/java/de/ids_mannheim/korap/query/parse/fcsql/FCSSRUQueryParser.java
index 96e12b1..fc0cfcf 100644
--- a/src/main/java/de/ids_mannheim/korap/query/parse/fcsql/FCSSRUQueryParser.java
+++ b/src/main/java/de/ids_mannheim/korap/query/parse/fcsql/FCSSRUQueryParser.java
@@ -25,7 +25,8 @@
 import eu.clarin.sru.server.fcs.parser.SimpleWithin;
 import eu.clarin.sru.server.fcs.parser.SimpleWithin.Scope;
 
-/**
+/** This class handles FCS query nodes from the FCSParser converting FCSQL to Java objects. 
+ * 
  * @author margaretha
  * 
  */
@@ -33,10 +34,18 @@
 
     private ExpressionParser expressionParser;
 
+    /** Constructs the FCSSRUQueryParser.
+     * 
+     */
     public FCSSRUQueryParser () {
         this.expressionParser = new ExpressionParser();
     }
 
+    /** Parses the given query node according to its type.
+     * @param queryNode an FCS a query node
+     * @return a koral object
+     * @throws KoralException
+     */
     public KoralObject parseQueryNode(QueryNode queryNode)
             throws KoralException {
 
@@ -66,17 +75,33 @@
         }
     }
     
+    /** Parses the given query segment into a koral object.
+     * @param segment a query segment
+     * @return a koral object representation of the query segment
+     * @throws KoralException
+     */
     private KoralObject parseQuerySegment(QuerySegment segment)
             throws KoralException {
         KoralObject object = expressionParser.parseExpression(segment.getExpression());
         return handleQuantifier(object, segment.getMinOccurs(), segment.getMaxOccurs());
     }
     
+    /** Parses the given query group into a koral object.
+     * @param group a koral group
+     * @return a koral object
+     * @throws KoralException
+     */
     private KoralObject parseQueryGroup(QueryGroup group) throws KoralException {
         KoralObject object = parseQueryNode(group.getFirstChild());
         return handleQuantifier(object, group.getMinOccurs(), group.getMaxOccurs());
     }
     
+    /** Parses FCSQL quantifier into a koral boundary and adds it to a koral group
+     * @param object a koral object
+     * @param minOccurs minimum occurrences
+     * @param maxOccurs maximum occurrences
+     * @return a koral group or the given koral object when minimum and maximum occurrences are exactly 1.
+     */
     private KoralObject handleQuantifier(KoralObject object, int minOccurs, int maxOccurs){
         if ((minOccurs == 1) && (maxOccurs == 1)) {
             return object;
@@ -92,7 +117,12 @@
         return koralGroup;
     }
     
-    private KoralObject parseWithinQuery(QueryWithWithin queryNode)
+    /** Parses a QueryWithWithin into a koral group.
+     * @param queryNode a query node of type QueryWithWithin
+     * @return a koral group
+     * @throws KoralException
+     */
+    private KoralGroup parseWithinQuery(QueryWithWithin queryNode)
             throws KoralException {
         KoralGroup koralGroup = new KoralGroup(KoralOperation.POSITION);
         koralGroup.setFrames(Arrays.asList(Frame.IS_AROUND));
@@ -104,6 +134,11 @@
         return koralGroup;
     }
 
+    /** Parses the scope of a QueryWithWithin into a koral span.
+     * @param scope the scope of a QueryWithWithin
+     * @return a koral span
+     * @throws KoralException
+     */
     private KoralSpan parseWithinScope(Scope scope) throws KoralException {
         if (scope == null) {
             throw new KoralException(StatusCodes.MALFORMED_QUERY,
@@ -129,6 +164,11 @@
         return new KoralSpan(new KoralTerm(contextSpan));
     }
 
+    /** Parses a query disjunction into a koral group.
+     * @param children a list of query nodes.
+     * @return a koral group with operation disjunction
+     * @throws KoralException
+     */
     private KoralGroup parseQueryDisjunction(List<QueryNode> children) throws KoralException {
         KoralGroup koralGroup = new KoralGroup(KoralOperation.DISJUNCTION);
         List<KoralObject> operands = new ArrayList<KoralObject>();
@@ -139,6 +179,11 @@
         return koralGroup;
     }
 
+    /** Parses a sequence query into a koral group.
+     * @param children a list query nodes.
+     * @return a koral group
+     * @throws KoralException
+     */
     private KoralGroup parseSequenceQuery(List<QueryNode> children)
             throws KoralException {
         KoralGroup koralGroup = new KoralGroup(KoralOperation.SEQUENCE);
@@ -154,7 +199,8 @@
             if (i > 0 && i < size - 1 && findEmptyToken(child)) {
                 QuerySegment qs = (QuerySegment) child;
                 if (isLastTokenEmpty) {
-                    updateBoundary(operands.get(operands.size() - 1), qs);
+                    KoralBoundary boundary = (KoralBoundary) operands.get(operands.size() - 1);
+                    updateBoundary(boundary, qs);
                 }
                 else {
                     operands.add(new KoralBoundary(qs.getMinOccurs(), qs
@@ -177,20 +223,35 @@
         return koralGroup;
     }
 
-    private boolean findEmptyToken(QueryNode child) {
-        if (child instanceof QuerySegment
-                && ((QuerySegment) child).getExpression() instanceof ExpressionWildcard) {
+    /** Determines if there is an empty token in the given query node.
+     * @param node a query node
+     * @return true if an empty token is found or false otherwise.
+     */
+    private boolean findEmptyToken(QueryNode node) {
+        if (node instanceof QuerySegment
+                && ((QuerySegment) node).getExpression() instanceof ExpressionWildcard) {
             return true;
         }
         return false;
     }
 
-    private void updateBoundary(KoralObject koralObject, QuerySegment qs) {
-        KoralBoundary boundary = (KoralBoundary) koralObject;
+    /** Updates the boundary properties with the parameters in the query segment.
+     * @param boundary a koral boundary
+     * @param qs a query segment
+     */
+    private void updateBoundary(KoralBoundary boundary, QuerySegment qs) {
         boundary.setMin(boundary.getMin() + qs.getMinOccurs());
         boundary.setMax(boundary.getMax() + qs.getMaxOccurs());
     }
 
+    /** Creates koral distances from KoralBoundary objects in the given operand list, 
+     * and adds the distances the koral group. Removes the KoralBoundary objects from 
+     * the operand list and returns the new operand list.
+     * 
+     * @param koralGroup a koral group
+     * @param operands a list of koral objects
+     * @return an updated operand lists without KoralBoundary objects 
+     */
     private List<KoralObject> createDistance(KoralGroup koralGroup, List<KoralObject> operands){
         boolean isSubGroupAdded = false;
         List<KoralObject> newOperands = new ArrayList<KoralObject>(
@@ -205,7 +266,7 @@
                 
                 if (koralGroup.getDistances() != null){
                     KoralObject lastOperand = newOperands.get(newOperands.size()-1);
-                    KoralGroup subGroup = createSubGroup(distances, lastOperand, operands.get(i+1));
+                    KoralGroup subGroup = createSequenceGroupWithDistance(distances, lastOperand, operands.get(i+1));
                     newOperands.remove(lastOperand);
                     newOperands.add(subGroup);
                     isSubGroupAdded = true;
@@ -228,7 +289,15 @@
         return newOperands;
     }
     
-    private KoralGroup createSubGroup(List<KoralDistance> distances, 
+    /** Creates a distance query, namely a koral group of operation sequence 
+     * with the given distances and operands.
+     *  
+     * @param distances a list of distances.
+     * @param operand an operand
+     * @param operand2 another operand
+     * @return a koral group
+     */
+    private KoralGroup createSequenceGroupWithDistance(List<KoralDistance> distances, 
             KoralObject operand, KoralObject operand2) {
         KoralGroup subGroup = new KoralGroup(KoralOperation.SEQUENCE);
         subGroup.setDistances(distances);
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/FCSQLQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/FCSQLQueryProcessor.java
index 369e8e3..06036ad 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/FCSQLQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/FCSQLQueryProcessor.java
@@ -2,6 +2,7 @@
 
 import java.util.Map;
 
+import de.ids_mannheim.korap.query.object.KoralObject;
 import de.ids_mannheim.korap.query.parse.fcsql.FCSSRUQueryParser;
 import de.ids_mannheim.korap.query.serialize.util.KoralException;
 import de.ids_mannheim.korap.query.serialize.util.StatusCodes;
@@ -11,7 +12,9 @@
 import eu.clarin.sru.server.fcs.parser.QueryParser;
 import eu.clarin.sru.server.fcs.parser.QueryParserException;
 
-/**
+/** FCSQLQueryProcessor is accountable for the serialization of FCSQL to KoralQuery.
+ * The KoralQuery is structured as a map containing parts of JSON-LD serializations of KoralObjects.  
+ * 
  * @author margaretha
  * 
  */
@@ -34,6 +37,10 @@
     private final QueryParser fcsParser = new QueryParser();
     private String version;
 
+    /** Constructs FCSQLQueryProcessor for the given query and version.
+     * @param query an FCS query string
+     * @param version the FCSQL version of the query
+     */
     public FCSQLQueryProcessor (String query, String version) {
         super();
         this.version = version;
@@ -74,6 +81,10 @@
         return true;
     }
 
+    /** Translates the given FCS query string into an FCSSSRUQuery object.
+     * @param query an FCS query string
+     * @return an FCSSRUQuery
+     */
     private FCSSRUQuery parseQueryStringtoFCSQuery(String query) {
         if ((query == null) || query.isEmpty())
             addError(StatusCodes.NO_QUERY,
@@ -100,9 +111,14 @@
         return fcsQuery;
     }
 
+    /** Generates a query map structure for the given FCS query node.
+     * 
+     * @param queryNode an FCS query node
+     * @throws KoralException
+     */
     private void parseFCSQueryToKoralQuery(QueryNode queryNode) throws KoralException {
         FCSSRUQueryParser parser = new FCSSRUQueryParser();
-        Object o = parser.parseQueryNode(queryNode);
+        KoralObject o = parser.parseQueryNode(queryNode);
         Map<String, Object> queryMap = MapBuilder.buildQueryMap(o);
         if (queryMap != null) requestMap.put("query", queryMap);
     }
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/MapBuilder.java b/src/main/java/de/ids_mannheim/korap/query/serialize/MapBuilder.java
index 9d1c2ee..f80c152 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/MapBuilder.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/MapBuilder.java
@@ -3,18 +3,23 @@
 import java.util.Map;
 
 import de.ids_mannheim.korap.query.object.KoralGroup;
+import de.ids_mannheim.korap.query.object.KoralObject;
 import de.ids_mannheim.korap.query.object.KoralSpan;
 import de.ids_mannheim.korap.query.object.KoralTerm;
 import de.ids_mannheim.korap.query.object.KoralTermGroup;
 import de.ids_mannheim.korap.query.object.KoralToken;
 
-/**
+/** 
  * @author margaretha
  * 
  */
 public class MapBuilder {
 
-    public static Map<String, Object> buildQueryMap(Object o) {
+    /** Builds a query map containing JSON-LD serialization parts of the given KoralObject.
+     * @param o
+     * @return a map
+     */
+    public static Map<String, Object> buildQueryMap(KoralObject o) {
         if (o != null) {
             if (o instanceof KoralToken) {
                 KoralToken token = (KoralToken) o;
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/util/KoralException.java b/src/main/java/de/ids_mannheim/korap/query/serialize/util/KoralException.java
index 34d4569..343c2ae 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/util/KoralException.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/util/KoralException.java
@@ -1,10 +1,12 @@
 package de.ids_mannheim.korap.query.serialize.util;
 
+/** Define a custom exception for errors in parsing into and serializing KoralQuery.
+ * 
+ * @author margaretha
+ *
+ */
 public class KoralException extends Exception{
-
-	/**
-	 * 
-	 */
+	
 	private static final long serialVersionUID = 5463242042200109417L;
 	private int statusCode;
 	
diff --git a/src/test/java/de/ids_mannheim/korap/query/serialize/FCSQLComplexTest.java b/src/test/java/de/ids_mannheim/korap/query/serialize/FCSQLComplexTest.java
index eed5aad..973c838 100644
--- a/src/test/java/de/ids_mannheim/korap/query/serialize/FCSQLComplexTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/serialize/FCSQLComplexTest.java
@@ -348,6 +348,15 @@
 
     @Test
     public void testWithinQuery() throws IOException {
+        query = "'grün' within s";
+        jsonLd = "{@type:koral:group,"
+                + "operation:operation:position,"
+                + "operands:["
+                + "{@type:koral:span,wrap:{@type:koral:term,key:s,foundry:base,layer:s}},"
+                + "{@type:koral:token,wrap:{@type:koral:term,key:grün,foundry:opennlp,layer:orth,type:type:regex,match:match:eq}}"
+                + "]}";
+        FCSQLQueryProcessorTest.runAndValidate(query, jsonLd);
+        
         query = "[cnx:pos=\"VVFIN\"] within s";
         jsonLd = "{@type:koral:group,"
                 + "operation:operation:position,"
@@ -419,6 +428,7 @@
 
     @Test
     public void testWrongQuery() throws IOException {
+        // expression should always be within a segment
         query = "!(mate:lemma=\"sein\" | mate:pos=\"PPOSS\")";
         error = FCSQLQueryProcessorTest.getError(new FCSQLQueryProcessor(query,
                 "2.0"));