Fixed KoralNode at method.

Change-Id: I16052735ef2aca8d04829d21f28c163714bf4da9
diff --git a/full/Changes b/full/Changes
index e789a76..45cab74 100644
--- a/full/Changes
+++ b/full/Changes
@@ -12,6 +12,7 @@
      (margaretha)
 6/12/2018
    - Added debug flags to mitigate log4j debugging performance (margaretha)
+   - Fixed KoralNode at() method (margaretha)
    
 # version 0.61.3
 17/10/2018
diff --git a/full/src/main/java/de/ids_mannheim/korap/rewrite/CollectionRewrite.java b/full/src/main/java/de/ids_mannheim/korap/rewrite/CollectionRewrite.java
index 091c1a8..153c3db 100644
--- a/full/src/main/java/de/ids_mannheim/korap/rewrite/CollectionRewrite.java
+++ b/full/src/main/java/de/ids_mannheim/korap/rewrite/CollectionRewrite.java
@@ -48,9 +48,11 @@
  */
 public class CollectionRewrite implements RewriteTask.RewriteQuery {
 
-    private static Logger jlog =
+    public static Logger jlog =
             LogManager.getLogger(CollectionRewrite.class);
 
+    public static boolean DEBUG = false;
+    
     public CollectionRewrite () {
         super();
     }
@@ -59,11 +61,13 @@
     private List<String> checkAvailability (JsonNode node,
             List<String> originalAvailabilities,
             List<String> updatedAvailabilities, boolean isOperationOr) {
-        try {
-            jlog.debug(JsonUtils.toJSON(node));
-        }
-        catch (KustvaktException e) {
-            e.printStackTrace();
+        if (DEBUG) {
+            try {
+                jlog.debug(JsonUtils.toJSON(node));
+            }
+            catch (KustvaktException e) {
+                e.printStackTrace();
+            }
         }
 
         if (node.has("operands")) {
@@ -105,11 +109,15 @@
 
             if (originalAvailabilities.contains(queryAvailability)
                     && matchOp.equals(KoralMatchOperator.EQUALS.toString())) {
-                jlog.debug("REMOVE " + queryAvailability);
+                if (DEBUG) {
+                    jlog.debug("REMOVE " + queryAvailability);
+                }
                 updatedAvailabilities.remove(queryAvailability);
             }
             else if (isOperationOr) {
-                jlog.debug("RESET availabilities 2");
+                if (DEBUG) { 
+                    jlog.debug("RESET availabilities 2");
+                }
                 updatedAvailabilities.clear();
                 updatedAvailabilities.addAll(originalAvailabilities);
                 return updatedAvailabilities;
@@ -150,14 +158,18 @@
             List<String> avalabilityCopy =
                     new ArrayList<String>(userAvailabilities.size());
             avalabilityCopy.addAll(userAvailabilities);
-            jlog.debug("Availabilities: "
-                    + Arrays.toString(userAvailabilities.toArray()));
+            if (DEBUG) {
+                jlog.debug("Availabilities: "
+                        + Arrays.toString(userAvailabilities.toArray()));
+            }
 
             userAvailabilities = checkAvailability(jsonNode.at("/collection"),
                     avalabilityCopy, userAvailabilities, false);
             if (!userAvailabilities.isEmpty()) {
                 builder.with(buildAvailability(avalabilityCopy));
-                jlog.debug("corpus query: " + builder.toString());
+                if (DEBUG) {
+                    jlog.debug("corpus query: " + builder.toString());
+                }
                 builder.setBaseQuery(builder.toJSON());
                 rewrittenNode = builder.mergeWith(jsonNode).at("/collection");
                 node.set("collection", rewrittenNode, identifier);
@@ -165,13 +177,17 @@
         }
         else {
             builder.with(buildAvailability(userAvailabilities));
-            jlog.debug("corpus query: " + builder.toString());
+            if (DEBUG) {
+                jlog.debug("corpus query: " + builder.toString());
+            }
             rewrittenNode =
                     JsonUtils.readTree(builder.toJSON()).at("/collection");
             node.set("collection", rewrittenNode, identifier);
         }
 
-        jlog.debug("REWRITES: " + node.at("/collection").toString());
+        node = node.at("/collection");
+        jlog.debug("REWRITES: " + node.toString());
+        
         return node.rawNode();
     }
 
diff --git a/full/src/main/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewrite.java b/full/src/main/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewrite.java
index 2154c47..320dcdb 100644
--- a/full/src/main/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewrite.java
+++ b/full/src/main/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewrite.java
@@ -27,7 +27,8 @@
     public JsonNode rewriteQuery (KoralNode node, KustvaktConfiguration config,
             User user) throws KustvaktException {
         if (node.has("collection")) {
-            findVCRef(user.getUsername(), node.at("/collection"));
+            node = node.at("/collection");
+            findVCRef(user.getUsername(), node);
         }
         return node.rawNode();
     }