collection query builder
diff --git a/pom.xml b/pom.xml
index ff64201..dd918d6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
     <modelVersion>4.0.0</modelVersion>
     <groupId>de.ids_mannheim.korap</groupId>
     <artifactId>Kustvakt-core</artifactId>
-    <version>0.59.1</version>
+    <version>0.59.2</version>
     <packaging>jar</packaging>
     <name>Kustvakt core</name>
     <description>Kustvakt core, basic rest api for testing purposes and default
@@ -131,6 +131,7 @@
                     <compilerCompliance>1.7</compilerCompliance>
                     <compilerTargetPlatform>1.7</compilerTargetPlatform>
                 </configuration>
+                <!--
                 <executions>
                     <execution>
                         <goals>
@@ -138,6 +139,7 @@
                         </goals>
                     </execution>
                 </executions>
+                -->
             </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
diff --git a/src/main/java/de/ids_mannheim/korap/config/JWTSigner.java b/src/main/java/de/ids_mannheim/korap/config/JWTSigner.java
index 8d1d08b..afca427 100644
--- a/src/main/java/de/ids_mannheim/korap/config/JWTSigner.java
+++ b/src/main/java/de/ids_mannheim/korap/config/JWTSigner.java
@@ -7,7 +7,6 @@
 import com.nimbusds.jwt.SignedJWT;
 import de.ids_mannheim.korap.exceptions.KustvaktException;
 import de.ids_mannheim.korap.exceptions.StatusCodes;
-import de.ids_mannheim.korap.user.Attributes;
 import de.ids_mannheim.korap.user.TokenContext;
 import de.ids_mannheim.korap.user.User;
 import de.ids_mannheim.korap.utils.TimeUtils;
diff --git a/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java b/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
index d9b5d8a..5352435 100644
--- a/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
+++ b/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
@@ -1,7 +1,6 @@
 package de.ids_mannheim.korap.config;
 
 import de.ids_mannheim.korap.interfaces.EncryptionIface;
-import de.ids_mannheim.korap.user.Attributes;
 import de.ids_mannheim.korap.utils.TimeUtils;
 import lombok.Getter;
 import org.apache.log4j.PropertyConfigurator;
diff --git a/src/main/java/de/ids_mannheim/korap/config/Scopes.java b/src/main/java/de/ids_mannheim/korap/config/Scopes.java
index a280c10..aea1dbd 100644
--- a/src/main/java/de/ids_mannheim/korap/config/Scopes.java
+++ b/src/main/java/de/ids_mannheim/korap/config/Scopes.java
@@ -1,6 +1,5 @@
 package de.ids_mannheim.korap.config;
 
-import de.ids_mannheim.korap.user.Attributes;
 import de.ids_mannheim.korap.utils.JsonUtils;
 
 import java.util.ArrayList;
diff --git a/src/main/java/de/ids_mannheim/korap/handlers/OAuthDb.java b/src/main/java/de/ids_mannheim/korap/handlers/OAuthDb.java
index e2ad1e2..f72140a 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/OAuthDb.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/OAuthDb.java
@@ -5,7 +5,7 @@
 import de.ids_mannheim.korap.exceptions.StatusCodes;
 import de.ids_mannheim.korap.exceptions.dbException;
 import de.ids_mannheim.korap.interfaces.db.PersistenceClient;
-import de.ids_mannheim.korap.user.Attributes;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.user.TokenContext;
 import de.ids_mannheim.korap.user.User;
 import de.ids_mannheim.korap.utils.BooleanUtils;
diff --git a/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java b/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java
index dd2657a..aeeb58a 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java
@@ -7,7 +7,7 @@
 import de.ids_mannheim.korap.interfaces.db.ResourceOperationIface;
 import de.ids_mannheim.korap.resources.KustvaktResource;
 import de.ids_mannheim.korap.resources.ResourceFactory;
-import de.ids_mannheim.korap.user.Attributes;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.user.User;
 import de.ids_mannheim.korap.utils.SqlBuilder;
 import org.slf4j.Logger;
diff --git a/src/main/java/de/ids_mannheim/korap/handlers/RowMapperFactory.java b/src/main/java/de/ids_mannheim/korap/handlers/RowMapperFactory.java
index 43d5af5..d18ea69 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/RowMapperFactory.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/RowMapperFactory.java
@@ -4,7 +4,7 @@
 import de.ids_mannheim.korap.config.URIParam;
 import de.ids_mannheim.korap.resources.KustvaktResource;
 import de.ids_mannheim.korap.resources.ResourceFactory;
-import de.ids_mannheim.korap.user.Attributes;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.user.KorAPUser;
 import de.ids_mannheim.korap.user.ShibUser;
 import de.ids_mannheim.korap.user.User;
diff --git a/src/main/java/de/ids_mannheim/korap/interfaces/defaults/KustvaktEncryption.java b/src/main/java/de/ids_mannheim/korap/interfaces/defaults/KustvaktEncryption.java
index 632b0e4..f45437e 100644
--- a/src/main/java/de/ids_mannheim/korap/interfaces/defaults/KustvaktEncryption.java
+++ b/src/main/java/de/ids_mannheim/korap/interfaces/defaults/KustvaktEncryption.java
@@ -4,7 +4,7 @@
 import de.ids_mannheim.korap.exceptions.KustvaktException;
 import de.ids_mannheim.korap.exceptions.StatusCodes;
 import de.ids_mannheim.korap.interfaces.EncryptionIface;
-import de.ids_mannheim.korap.user.Attributes;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.user.User;
 import de.ids_mannheim.korap.web.utils.KustvaktMap;
 import edu.emory.mathcs.backport.java.util.Collections;
diff --git a/src/main/java/de/ids_mannheim/korap/resource/LayerMapper.java b/src/main/java/de/ids_mannheim/korap/resource/LayerMapper.java
index ebe4a2e..44e367d 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/LayerMapper.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/LayerMapper.java
@@ -1,7 +1,7 @@
 package de.ids_mannheim.korap.resource;
 
 import de.ids_mannheim.korap.config.KustvaktConfiguration;
-import de.ids_mannheim.korap.user.Attributes;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.user.Userdata;
 
 /**
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionCleanupFilter.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionCleanupFilter.java
index 14fcf15..46c39f9 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionCleanupFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionCleanupFilter.java
@@ -57,29 +57,6 @@
         return root;
     }
 
-
-    // return null deletes node, if node return replace at level -1
-    @Deprecated
-    private JsonNode processNodes (JsonNode jsonNode) {
-        if (jsonNode.isObject()) {
-            if (jsonNode.has("operands")) {
-                JsonNode node = jsonNode.at("/operands");
-                int count = node.size();
-                if (count == 1) {
-                    // move to super node if any
-                    return node.path(0);
-                }
-                else if (count == 0) {
-                    // remove container
-                    return null;
-                }
-                return jsonNode;
-            }
-        }
-        return JsonUtils.createArrayNode();
-    }
-
-
     @Override
     public JsonNode postProcess (KoralNode node) {
         return null;
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionConstraint.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionConstraint.java
index 4173bbd..13e6196 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionConstraint.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionConstraint.java
@@ -1,6 +1,7 @@
 package de.ids_mannheim.korap.resource.rewrite;
 
 import com.fasterxml.jackson.databind.JsonNode;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.config.BeanInjectable;
 import de.ids_mannheim.korap.config.ContextHolder;
 import de.ids_mannheim.korap.config.KustvaktConfiguration;
@@ -20,7 +21,7 @@
     public JsonNode preProcess (KoralNode node, KustvaktConfiguration config,
             User user) {
         if (node.get("@type").equals("koral:doc")) {
-            if (node.get("key").equals("corpusID") && !check(node, user)) {
+            if (node.get("key").equals(Attributes.CORPUS_SIGLE) && !check(node, user)) {
                 node.removeNode();
                 // todo: add message that node was removed!
             }
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/IdWriter.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/IdWriter.java
index 86026aa..f0b1200 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/IdWriter.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/IdWriter.java
@@ -14,7 +14,6 @@
 
     private int counter;
 
-
     public IdWriter () {
         this.counter = 0;
     }
@@ -31,8 +30,6 @@
         return node.rawNode();
     }
 
-
-    // fixme: koral token --> how does grouping behave?!
     private String extractToken (JsonNode token) {
         JsonNode wrap = token.path("wrap");
         if (!wrap.isMissingNode())
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/KoralNode.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/KoralNode.java
index fe3f6cb..16debc8 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/KoralNode.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/KoralNode.java
@@ -18,19 +18,17 @@
     private JsonNode node;
     private KoralRewriteBuilder builder;
     private boolean remove;
-    private final String target;
 
 
-    private KoralNode (String target, JsonNode node) {
+    private KoralNode (JsonNode node) {
         this.node = node;
-        this.target = target;
         this.builder = new KoralRewriteBuilder();
         this.remove = false;
     }
 
 
     public static KoralNode wrapNode (JsonNode node) {
-        return new KoralNode(null, node) {};
+        return new KoralNode(node) {};
     }
 
 
@@ -40,22 +38,6 @@
     }
 
 
-    @Deprecated
-    public boolean setNode (Object path) {
-        JsonNode n = null;
-        if (this.node.isObject() && this.node.has((String) path))
-            n = this.node.path((String) path);
-        else if (this.node.isArray() && this.node.has((int) path))
-            n = this.node.path((int) path);
-
-        if (n != null) {
-            this.node = n;
-            return true;
-        }
-        return false;
-    }
-
-
     public void put (String name, Object value) {
 
         if (this.node.isObject() && this.node.path(name).isMissingNode()) {
@@ -64,6 +46,8 @@
                 node.put(name, (String) value);
             else if (value instanceof Integer)
                 node.put(name, (Integer) value);
+            else if (value instanceof JsonNode)
+                node.put(name, (JsonNode) value);
             builder.setOperation("injection");
             builder.build(this.node);
         }
@@ -92,15 +76,34 @@
     }
 
 
-    public void replace (String name, String value) {
+    public void replace (String name, Object value) {
         if (this.node.isObject() && this.node.has(name)) {
             ObjectNode n = (ObjectNode) this.node;
-            n.put(name, value);
+            if (value instanceof String)
+                n.put(name, (String) value);
+            else if (value instanceof Integer)
+                n.put(name, (Integer) value);
+            else if (value instanceof JsonNode)
+                n.put(name, (JsonNode) value);
             builder.setOperation("override");
             builder.build(this.node);
         }
     }
 
+    public void set (String name, Object value) {
+        if (this.node.isObject()) {
+            ObjectNode n = (ObjectNode) this.node;
+            if (value instanceof String)
+                n.put(name, (String) value);
+            else if (value instanceof Integer)
+                n.put(name, (Integer) value);
+            else if (value instanceof JsonNode)
+                n.put(name, (JsonNode) value);
+            builder.setOperation("insertion");
+            builder.build(this.node);
+        }
+    }
+
 
     public String get (String name) {
         if (this.node.isObject())
@@ -109,8 +112,8 @@
     }
 
 
-    public JsonNode at (String name) {
-        return this.node.at(name);
+    public KoralNode at (String name) {
+        return KoralNode.wrapNode(this.node.at(name));
     }
 
 
@@ -138,12 +141,8 @@
     }
 
 
-    public final String target () {
-        return this.target;
-    }
-
     //todo: 21.10.15 -- redo with better return policies!
-    private static class KoralRewriteBuilder {
+    public static class KoralRewriteBuilder {
 
         private Map<String, String> map;
 
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/PublicCollection.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/PublicCollection.java
index 597a407..a8efce3 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/PublicCollection.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/PublicCollection.java
@@ -1,21 +1,25 @@
 package de.ids_mannheim.korap.resource.rewrite;
 
 import com.fasterxml.jackson.databind.JsonNode;
-import de.ids_mannheim.korap.config.BeanInjectable;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.config.KustvaktConfiguration;
 import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.exceptions.StatusCodes;
 import de.ids_mannheim.korap.resources.Corpus;
+import de.ids_mannheim.korap.resources.KustvaktResource;
 import de.ids_mannheim.korap.security.ac.ResourceFinder;
 import de.ids_mannheim.korap.user.User;
-import de.ids_mannheim.korap.utils.CollectionQueryBuilder3;
+import de.ids_mannheim.korap.utils.KoralCollectionQueryBuilder;
+import de.ids_mannheim.korap.utils.JsonUtils;
 
+import java.util.ArrayList;
 import java.util.Set;
 
 /**
  * @author hanl
  * @date 04/07/2015
  */
-public class PublicCollection implements RewriteTask.RewriteNodeAt {
+public class PublicCollection implements RewriteTask.RewriteBefore {
 
     public PublicCollection () {
         super();
@@ -27,43 +31,35 @@
     public JsonNode preProcess (KoralNode node, KustvaktConfiguration config,
             User user) {
         JsonNode subnode = node.rawNode();
-        // todo: test
+
         if (!subnode.at("/collection").findValuesAsText("key")
-                .contains("corpusID")) {
-            //todo: inject public collection node
-            if (user != null) {
-                try {
-                    ResourceFinder finder = ResourceFinder.init(user,
-                            Corpus.class);
-                    Set<String> ids = finder.getIds();
-                    createNode(ids);
+                .contains(Attributes.CORPUS_SIGLE)) {
+            KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder();
+            if (subnode.has("collection"))
+                b.setBaseQuery(JsonUtils.toJSON(subnode));
+
+            try {
+                Set resources = ResourceFinder.search(user, Corpus.class);
+                ArrayList<KustvaktResource> list = new ArrayList(resources);
+
+                if (list.isEmpty())
+                    throw new KustvaktException(StatusCodes.REQUEST_INVALID,
+                            "No resources found for user", user.getUsername());
+
+                for (int i = 0; i < list.size(); i++) {
+                    if (i > 0)
+                        b.or();
+                    b.with(Attributes.CORPUS_SIGLE+"=" + list.get(i).getPersistentID());
                 }
-                catch (KustvaktException e) {
-                    e.printStackTrace();
-                    //todo: 20.10.15 - 21.10.15
-                }
+                JsonNode rewritten = JsonUtils.readTree(b.toJSON());
+                node.set("collection", rewritten.at("/collection"));
+            }
+            catch (KustvaktException e) {
+                e.printStackTrace();
+                // todo:
             }
         }
-        return subnode;
+
+        return node.rawNode();
     }
-
-
-    //todo: 20.10.15
-    private JsonNode createNode (Set<String> ids) {
-        JsonNode node = CollectionQueryBuilder3.Utils.buildDocGroup();
-        return node;
-    }
-
-
-    @Override
-    public JsonNode postProcess (KoralNode node) {
-        return null;
-    }
-
-
-    @Override
-    public String at () {
-        return "/collection";
-    }
-
 }
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandler.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandler.java
index 3569834..746c3a0 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandler.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandler.java
@@ -7,6 +7,7 @@
 import de.ids_mannheim.korap.exceptions.KustvaktException;
 import de.ids_mannheim.korap.user.User;
 import de.ids_mannheim.korap.utils.JsonUtils;
+import org.apache.xpath.SourceTree;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -174,6 +175,7 @@
     }
 
 
+    // fixme: redo with first, second iteration and push clean up filters into second run
     public String preProcess (String json, User user) {
         return JsonUtils.toJSON(preProcess(JsonUtils.readTree(json), user));
     }
@@ -246,17 +248,18 @@
                 if ((rwa.at() != null && !node.at(rwa.at()).isMissingNode()))
                     next = node.at(rwa.at());
             }
+
             try {
-                if (!post && task instanceof RewriteTask.RewriteBefore)
+                if (!post & task instanceof RewriteTask.RewriteBefore)
                     ((RewriteTask.RewriteBefore) task).preProcess(
                             KoralNode.wrapNode(next), this.config, user);
-                else
+                else if (task instanceof RewriteTask.RewriteAfter)
                     ((RewriteTask.RewriteAfter) task).postProcess(KoralNode
                             .wrapNode(next));
             }
             catch (KustvaktException e) {
                 jlog.error("Error in rewrite processor {} for node {}", task
-                        .getClass().getSimpleName(), node.toString());
+                        .getClass().getSimpleName(), next.toString());
                 e.printStackTrace();
             }
         }
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteTask.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteTask.java
index d9a3e4b..2c7fa06 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteTask.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteTask.java
@@ -11,6 +11,10 @@
  */
 public interface RewriteTask {
 
+
+    /**
+     * unspecified query rewrite that gets injected the entire root node during preprocessing
+     */
     interface RewriteBefore extends RewriteTask {
         /**
          * @param node
@@ -70,27 +74,4 @@
      */
     interface RewriteKoralToken extends RewriteBefore {}
 
-    /**
-     * query rewrites get injected the entire query from root
-     * containing all child nodes
-     * <p/> {@link RewriteQuery} does not allow the deletion of the
-     * root node or subnode through KoralNode.
-     * The
-     * {@link de.ids_mannheim.korap.resource.rewrite.RewriteHandler}
-     * will igonore respecitve invalid requests
-     */
-    @Deprecated
-    interface RewriteQuery extends RewriteBefore, RewriteAfter {}
-
-    /**
-     * Koral term nodes that are subject to rewrites
-     * Be aware that node rewrites are processed before query
-     * rewrites. Thus query rewrite may override previous node
-     * rewrites
-     * <p/> {@link RewriteNode} rewrite supports the deletion of the
-     * respective node by simply setting the node invalid in KoralNode
-     */
-    @Deprecated
-    interface RewriteNode extends RewriteBefore {}
-
 }
diff --git a/src/main/java/de/ids_mannheim/korap/security/PolicyCondition.java b/src/main/java/de/ids_mannheim/korap/security/PolicyCondition.java
index 6ec5450..a7adbf8 100644
--- a/src/main/java/de/ids_mannheim/korap/security/PolicyCondition.java
+++ b/src/main/java/de/ids_mannheim/korap/security/PolicyCondition.java
@@ -1,6 +1,6 @@
 package de.ids_mannheim.korap.security;
 
-import de.ids_mannheim.korap.user.Attributes;
+import de.ids_mannheim.korap.config.Attributes;
 import lombok.Getter;
 
 import java.util.HashMap;
diff --git a/src/main/java/de/ids_mannheim/korap/security/ac/PolicyDao.java b/src/main/java/de/ids_mannheim/korap/security/ac/PolicyDao.java
index e0e33ce..181d435 100644
--- a/src/main/java/de/ids_mannheim/korap/security/ac/PolicyDao.java
+++ b/src/main/java/de/ids_mannheim/korap/security/ac/PolicyDao.java
@@ -10,7 +10,7 @@
 import de.ids_mannheim.korap.security.Parameter;
 import de.ids_mannheim.korap.security.PolicyCondition;
 import de.ids_mannheim.korap.security.SecurityPolicy;
-import de.ids_mannheim.korap.user.Attributes;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.user.User;
 import de.ids_mannheim.korap.utils.BooleanUtils;
 import de.ids_mannheim.korap.utils.StringUtils;
diff --git a/src/main/java/de/ids_mannheim/korap/security/ac/ResourceFinder.java b/src/main/java/de/ids_mannheim/korap/security/ac/ResourceFinder.java
index 4dffda5..d31a2f7 100644
--- a/src/main/java/de/ids_mannheim/korap/security/ac/ResourceFinder.java
+++ b/src/main/java/de/ids_mannheim/korap/security/ac/ResourceFinder.java
@@ -11,7 +11,7 @@
 import de.ids_mannheim.korap.security.PermissionsBuffer;
 import de.ids_mannheim.korap.security.PolicyCondition;
 import de.ids_mannheim.korap.security.SecurityPolicy;
-import de.ids_mannheim.korap.user.Attributes;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.user.User;
 import lombok.NonNull;
 import org.slf4j.Logger;
@@ -123,7 +123,12 @@
     // todo: should this be working?
     public static <T extends KustvaktResource> Set<T> search (User user,
             Class<T> clazz) throws KustvaktException {
-        return search(null, true, user, clazz, Permissions.Permission.READ);
+        Set set = new HashSet();
+        if (user != null && !User.UserFactory.isDemo(user.getUsername()))
+            set = search(null, true, user, clazz, Permissions.Permission.READ);
+        if (set.isEmpty())
+            set = searchPublic(clazz);
+        return set;
     }
 
 
diff --git a/src/main/java/de/ids_mannheim/korap/security/auth/APIAuthentication.java b/src/main/java/de/ids_mannheim/korap/security/auth/APIAuthentication.java
index 97b0e1b..69ef5bf 100644
--- a/src/main/java/de/ids_mannheim/korap/security/auth/APIAuthentication.java
+++ b/src/main/java/de/ids_mannheim/korap/security/auth/APIAuthentication.java
@@ -7,11 +7,10 @@
 import de.ids_mannheim.korap.exceptions.KustvaktException;
 import de.ids_mannheim.korap.exceptions.StatusCodes;
 import de.ids_mannheim.korap.interfaces.AuthenticationIface;
-import de.ids_mannheim.korap.user.Attributes;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.user.TokenContext;
 import de.ids_mannheim.korap.user.User;
 import de.ids_mannheim.korap.utils.NamingUtils;
-import de.ids_mannheim.korap.utils.StringUtils;
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.CacheManager;
 import net.sf.ehcache.Element;
diff --git a/src/main/java/de/ids_mannheim/korap/security/auth/BasicHttpAuth.java b/src/main/java/de/ids_mannheim/korap/security/auth/BasicHttpAuth.java
index 16e0298..ccad916 100644
--- a/src/main/java/de/ids_mannheim/korap/security/auth/BasicHttpAuth.java
+++ b/src/main/java/de/ids_mannheim/korap/security/auth/BasicHttpAuth.java
@@ -7,12 +7,11 @@
 import de.ids_mannheim.korap.interfaces.AuthenticationIface;
 import de.ids_mannheim.korap.interfaces.EncryptionIface;
 import de.ids_mannheim.korap.interfaces.db.EntityHandlerIface;
-import de.ids_mannheim.korap.user.Attributes;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.user.KorAPUser;
 import de.ids_mannheim.korap.user.TokenContext;
 import de.ids_mannheim.korap.user.User;
 import de.ids_mannheim.korap.utils.NamingUtils;
-import de.ids_mannheim.korap.utils.StringUtils;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.oltu.oauth2.common.utils.OAuthUtils;
 
diff --git a/src/main/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManager.java b/src/main/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManager.java
index 28cb802..97e67af 100644
--- a/src/main/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManager.java
+++ b/src/main/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManager.java
@@ -1,6 +1,7 @@
 package de.ids_mannheim.korap.security.auth;
 
 import de.ids_mannheim.korap.auditing.AuditRecord;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.config.BeansFactory;
 import de.ids_mannheim.korap.config.KustvaktConfiguration;
 import de.ids_mannheim.korap.config.URIParam;
@@ -13,7 +14,6 @@
 import de.ids_mannheim.korap.interfaces.db.UserDataDbIface;
 import de.ids_mannheim.korap.user.*;
 import de.ids_mannheim.korap.utils.NamingUtils;
-import de.ids_mannheim.korap.utils.StringUtils;
 import de.ids_mannheim.korap.utils.TimeUtils;
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.CacheManager;
diff --git a/src/main/java/de/ids_mannheim/korap/security/auth/OpenIDconnectAuthentication.java b/src/main/java/de/ids_mannheim/korap/security/auth/OpenIDconnectAuthentication.java
index 98a8268..e8de6c7 100644
--- a/src/main/java/de/ids_mannheim/korap/security/auth/OpenIDconnectAuthentication.java
+++ b/src/main/java/de/ids_mannheim/korap/security/auth/OpenIDconnectAuthentication.java
@@ -8,11 +8,10 @@
 import de.ids_mannheim.korap.handlers.OAuthDb;
 import de.ids_mannheim.korap.interfaces.AuthenticationIface;
 import de.ids_mannheim.korap.interfaces.db.PersistenceClient;
-import de.ids_mannheim.korap.user.Attributes;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.user.TokenContext;
 import de.ids_mannheim.korap.user.User;
 import de.ids_mannheim.korap.utils.NamingUtils;
-import de.ids_mannheim.korap.utils.StringUtils;
 import net.sf.ehcache.CacheManager;
 import net.sf.ehcache.Element;
 import org.springframework.cache.annotation.CacheEvict;
diff --git a/src/main/java/de/ids_mannheim/korap/security/auth/SessionAuthentication.java b/src/main/java/de/ids_mannheim/korap/security/auth/SessionAuthentication.java
index ceb1284..5caab24 100644
--- a/src/main/java/de/ids_mannheim/korap/security/auth/SessionAuthentication.java
+++ b/src/main/java/de/ids_mannheim/korap/security/auth/SessionAuthentication.java
@@ -5,7 +5,7 @@
 import de.ids_mannheim.korap.exceptions.StatusCodes;
 import de.ids_mannheim.korap.interfaces.AuthenticationIface;
 import de.ids_mannheim.korap.interfaces.EncryptionIface;
-import de.ids_mannheim.korap.user.Attributes;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.user.TokenContext;
 import de.ids_mannheim.korap.user.User;
 import de.ids_mannheim.korap.utils.TimeUtils;
diff --git a/src/main/java/de/ids_mannheim/korap/user/Attributes.java b/src/main/java/de/ids_mannheim/korap/user/Attributes.java
deleted file mode 100644
index 9d4761b..0000000
--- a/src/main/java/de/ids_mannheim/korap/user/Attributes.java
+++ /dev/null
@@ -1,162 +0,0 @@
-package de.ids_mannheim.korap.user;
-
-public class Attributes {
-
-    public static final String AUTHORIZATION = "Authorization";
-    public static final String SESSION_AUTHENTICATION = "session_token";
-    public static final String API_AUTHENTICATION = "api_token";
-    public static final String OAUTH2_AUTHORIZATION = "bearer";
-    public static final String OPENID_AUTHENTICATION = "id_token";
-    public static final String BASIC_AUTHENTICATION = "basic";
-
-    public static final String CLIENT_ID = "client_id";
-    public static final String CLIENT_SECRET = "client_secret";
-    public static final String SCOPES = "scopes";
-
-    public static final String PUBLIC_GROUP = "public";
-
-    public static final String SERVICE_ACCESS = "service_access";
-    public static final String USER = "KorapUser";
-    public static final String SHIBUSER = "ShibUser";
-    public static final String DEMO_DISPLAY = "Anonymous";
-    public static final String DEMOUSER_PASSWORD = "demo";
-
-    public static final String SETTINGS = "LocalSettings";
-    //    public static final String STORAGE_SETTINGS = "StorageSettings";
-
-    public static final String QUERY_ABBREVIATION = "Q";
-    public static final String LAYER = "layer";
-
-    public static final String TYPE = "type";
-
-    public static final String ID = "ID";
-    @Deprecated
-    //refactor
-    public static final String UID = "accountID";
-    public static final String USERNAME = "username";
-    public static final String PASSWORD = "password";
-    public static final String GENDER = "gender";
-    public static final String FIRSTNAME = "firstName";
-    public static final String LASTNAME = "lastName";
-    public static final String PHONE = "phone";
-    public static final String INSTITUTION = "institution";
-    public static final String EMAIL = "email";
-    public static final String ADDRESS = "address";
-    public static final String COUNTRY = "country";
-    public static final String IPADDRESS = "ipaddress";
-    // deprcated, use created
-    public static final String ACCOUNT_CREATION = "account_creation";
-    public static final String ACCOUNTLOCK = "account_lock";
-    public static final String ACCOUNTLINK = "account_link";
-    public static final String URI = "uri";
-    public static final String URI_FRAGMENT = "uri_fragment";
-    public static final String URI_EXPIRATION = "uri_expiration";
-    public static final String PRIVATE_USAGE = "privateUsage";
-
-    /**
-     * token context
-     */
-    public static final String TOKEN = "authToken";
-    public static final String TOKEN_EXPIRATION = "tokenExpires";
-    public static final String TOKEN_CREATION = "tokenCreated";
-    public static final String USER_AGENT = "User-Agent";
-    public static final String HOST = "userIP";
-
-    public static final String QUERY_PARAM_URI = "uri";
-    public static final String QUERY_PARAM_USER = "user";
-
-    /**
-     * shibboleth attribute names
-     */
-    public static final String EPPN = "eppn";
-    public static final String COMMON_NAME = "cn";
-    public static final String SURNAME = "sn";
-
-    public static final String EDUPERSON = "eduPersonPrincipalName";
-    public static final String CN = "cn";
-    public static final String MAIL = "mail";
-    public static final String EDU_AFFIL = "eduPersonScopedAffiliation";
-
-    /**
-     * resource mappings
-     */
-
-    public static final String RID = "id";
-    public static final String OWNER = "owner";
-    public static final String NAME = "name";
-    public static final String DESCRIPTION = "description";
-
-    public static final String REF_CORPUS = "refCorpus";
-    public static final String QUERY = "query";
-    public static final String CACHE = "cache";
-    public static final String DOCIDS = "docIDs";
-    public static final String FOUNDRIES = "foundries";
-    public static final String DEFAULT_VALUE = "defaultColl";
-
-    public static final String FILE_FORMAT_FOR_EXPORT = "fileFormatForExport";
-    public static final String FILENAME_FOR_EXPORT = "fileNameForExport";
-    @Deprecated
-    public static final String ITEM_FOR_SIMPLE_ANNOTATION = "itemForSimpleAnnotation";
-    public static final String LEFT_CONTEXT_ITEM_FOR_EXPORT = "leftContextItemForExport";
-    public static final String LEFT_CONTEXT_SIZE_FOR_EXPORT = "leftContextSizeForExport";
-    public static final String LOCALE = "locale";
-    public static final String LEFT_CONTEXT_ITEM = "leftContextItem";
-    public static final String LEFT_CONTEXT_SIZE = "leftContextSize";
-    public static final String RIGHT_CONTEXT_ITEM = "rightContextItem";
-    public static final String RIGHT_CONTEXT_ITEM_FOR_EXPORT = "rightContextItemForExport";
-    public static final String RIGHT_CONTEXT_SIZE = "rightContextSize";
-    public static final String RIGHT_CONTEXT_SIZE_FOR_EXPORT = "rightContextSizeForExport";
-    public static final String SELECTED_COLLECTION = "selectedCollection";
-    public static final String QUERY_LANGUAGE = "queryLanguage";
-    public static final String PAGE_LENGTH = "pageLength";
-    public static final String METADATA_QUERY_EXPERT_MODUS = "metadataQueryExpertModus";
-    @Deprecated
-    public static final String SEARCH_SETTINGS_TAB = "searchSettingsTab";
-    @Deprecated
-    public static final String SELECTED_BROWSER_PROPERTY = "selectedBrowserProperty";
-    @Deprecated
-    public static final String SELECTED_CONTEXT_ITEM = "selectedContextItem";
-    @Deprecated
-    public static final String SELECTED_GRAPH_TYPE = "selectedGraphType";
-    @Deprecated
-    public static final String SELECTED_SORT_TYPE = "selectedSortType";
-    @Deprecated
-    public static final String SELECTED_VIEW_FOR_SEARCH_RESULTS = "selectedViewForSearchResults";
-    public static final String COLLECT_AUDITING_DATA = "collectData";
-
-    /**
-     * default layers
-     */
-    public static final String DEFAULT_POS_FOUNDRY = "POSFoundry";
-    public static final String DEFAULT_LEMMA_FOUNDRY = "lemmaFoundry";
-    public static final String DEFAULT_CONST_FOUNDRY = "constFoundry";
-    public static final String DEFAULT_REL_FOUNDRY = "relFoundry";
-
-    /**
-     * db column keys
-     */
-
-    public static final String SELF_REF = "self";
-
-    public static final String SYM_USE = "sym_use";
-    public static final String COMMERCIAL = "commercial";
-    public static final String LICENCE = "licence";
-    public static final String QUERY_ONLY = "query_only";
-    public static final String EXPORT = "export";
-    public static final String TIME_SPANS = "spans";
-    public static final String RANGE = "range";
-
-    public static final String GROUP_ID = "group_id";
-    public static final String CREATED = "created";
-    public static final String CREATOR = "creator";
-    public static final String ENABLED = "enabled";
-    public static final String EXPIRE = "expired";
-    public static final String TARGET_ID = "target_id";
-    public static final String IP_RANG = "ip_range";
-    public static final String PERSISTENT_ID = "persistent_id";
-    public static final String DISABLED = "disabled";
-    public static final String USER_ID = "user_id";
-    public static final String PARENT_ID = "parent_id";
-    //    public static final String
-
-}
diff --git a/src/main/java/de/ids_mannheim/korap/user/TokenContext.java b/src/main/java/de/ids_mannheim/korap/user/TokenContext.java
index 8cf5ad8..c7da851 100644
--- a/src/main/java/de/ids_mannheim/korap/user/TokenContext.java
+++ b/src/main/java/de/ids_mannheim/korap/user/TokenContext.java
@@ -2,6 +2,7 @@
 
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.utils.JsonUtils;
 import lombok.AccessLevel;
 import lombok.Data;
diff --git a/src/main/java/de/ids_mannheim/korap/user/User.java b/src/main/java/de/ids_mannheim/korap/user/User.java
index 99f52d1..af1e90a 100644
--- a/src/main/java/de/ids_mannheim/korap/user/User.java
+++ b/src/main/java/de/ids_mannheim/korap/user/User.java
@@ -1,6 +1,7 @@
 package de.ids_mannheim.korap.user;
 
 import com.fasterxml.jackson.databind.JsonNode;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.config.ParamFields;
 import de.ids_mannheim.korap.utils.JsonUtils;
 import de.ids_mannheim.korap.utils.TimeUtils;
diff --git a/src/main/java/de/ids_mannheim/korap/user/UserDetails.java b/src/main/java/de/ids_mannheim/korap/user/UserDetails.java
index a994eee..d4e84c6 100644
--- a/src/main/java/de/ids_mannheim/korap/user/UserDetails.java
+++ b/src/main/java/de/ids_mannheim/korap/user/UserDetails.java
@@ -1,5 +1,7 @@
 package de.ids_mannheim.korap.user;
 
+import de.ids_mannheim.korap.config.Attributes;
+
 /**
  * @author hanl
  * @date 22/01/2016
diff --git a/src/main/java/de/ids_mannheim/korap/user/UserSettings.java b/src/main/java/de/ids_mannheim/korap/user/UserSettings.java
index 8eb855a..763b180 100644
--- a/src/main/java/de/ids_mannheim/korap/user/UserSettings.java
+++ b/src/main/java/de/ids_mannheim/korap/user/UserSettings.java
@@ -1,5 +1,7 @@
 package de.ids_mannheim.korap.user;
 
+import de.ids_mannheim.korap.config.Attributes;
+
 /**
  * @author hanl
  * @date 28/01/2016
diff --git a/src/main/java/de/ids_mannheim/korap/utils/CollectionQueryBuilder3.java b/src/main/java/de/ids_mannheim/korap/utils/CollectionQueryBuilder3.java
deleted file mode 100644
index d26d910..0000000
--- a/src/main/java/de/ids_mannheim/korap/utils/CollectionQueryBuilder3.java
+++ /dev/null
@@ -1,191 +0,0 @@
-package de.ids_mannheim.korap.utils;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import de.ids_mannheim.korap.query.serialize.CollectionQueryProcessor;
-
-import java.util.Map;
-
-/**
- * convenience builder class for collection query
- * 
- * @author hanl
- * @date 16/09/2014
- */
-public class CollectionQueryBuilder3 {
-
-    public enum EQ {
-        EQUAL, UNEQUAL
-    }
-
-    private boolean verbose;
-    private JsonNode base;
-    private StringBuilder builder;
-
-
-    public CollectionQueryBuilder3 () {
-        this(false);
-    }
-
-
-    public CollectionQueryBuilder3 (boolean verbose) {
-        this.verbose = verbose;
-        this.builder = new StringBuilder();
-        this.base = null;
-    }
-
-
-    //    /**
-    //     * convencience method for equal field value search operation
-    //     * @param field
-    //     * @param value
-    //     * @return
-    //     */
-    //    public CollectionQueryBuilder3 eq(String field, String value) {
-    //        fieldValue(field, "match:eq", value);
-    //        return this;
-    //    }
-    //
-    //    /**
-    //     * convencience method for unequal field value search operation
-    //     * @param field
-    //     * @param value
-    //     * @return
-    //     */
-    //    public CollectionQueryBuilder3 uneq(String field, String value) {
-    //        fieldValue(field, "match:ne", value);
-    //        return this;
-    //    }
-
-    /**
-     * raw method for field - value pair adding. Supports all
-     * operators (leq, geq, contains, etc.)
-     * 
-     * @param field
-     * @param op
-     * @param value
-     * @return
-     */
-    public CollectionQueryBuilder3 fieldValue (String field, String op,
-            String value) {
-        if (base == null)
-            this.builder.append(field + op + value);
-        else {
-            JsonNode node = Utils.buildDoc(field, value, op);
-            appendToBaseGroup(node);
-        }
-        return this;
-    }
-
-
-    /**
-     * element can be a more complex sub query like
-     * (textClass=freizeit & corpusID=WPD)
-     * 
-     * @param query
-     *            will be parenthised in order to make sub query
-     *            element
-     * @return
-     */
-    public CollectionQueryBuilder3 addQuery (String query) {
-        if (!query.startsWith("(") && !query.endsWith(")"))
-            query = "(" + query + ")";
-
-        if (base != null) {
-            CollectionQueryProcessor tree = new CollectionQueryProcessor(
-                    this.verbose);
-            tree.process(query);
-            JsonNode map = JsonUtils.valueToTree(tree.getRequestMap().get(
-                    "collection"));
-            appendToBaseGroup(map);
-        }
-        else
-            this.builder.append(query);
-        return this;
-    }
-
-
-    public CollectionQueryBuilder3 and () {
-        this.builder.append(" & ");
-        return this;
-    }
-
-
-    public CollectionQueryBuilder3 or () {
-        this.builder.append(" | ");
-        return this;
-    }
-
-
-    private Object build () {
-        Object request = base;
-        if (request == null) {
-            CollectionQueryProcessor tree = new CollectionQueryProcessor(
-                    this.verbose);
-            tree.process(this.builder.toString());
-            Map r = tree.getRequestMap();
-            r.remove("query");
-            r.remove("meta");
-            request = r;
-        }
-        return request;
-    }
-
-
-    /**
-     * sets base query. All consequent queries are added to the first
-     * koral:docGroup within the collection base query
-     * If no group in base query, consequent queries are skipped.
-     * 
-     * @param query
-     */
-    public CollectionQueryBuilder3 setBaseQuery (String query) {
-        this.base = JsonUtils.readTree(query);
-        return this;
-    }
-
-
-    public String toJSON () {
-        return JsonUtils.toJSON(build());
-    }
-
-
-    private CollectionQueryBuilder3 appendToBaseGroup (JsonNode node) {
-        if (base.at("/collection/@type").asText().equals("koral:docGroup")) {
-            ArrayNode group = (ArrayNode) base.at("/collection/operands");
-            if (node instanceof ArrayNode)
-                group.addAll((ArrayNode) node);
-            else
-                group.add(node);
-        }
-        else
-            throw new IllegalArgumentException("No group found to add to!");
-        // fixme: if base is a doc only, this function is not supported. requirement is a koral:docGroup, since
-        // combination operator is unknown otherwise
-        return this;
-    }
-
-    public static class Utils {
-
-        public static JsonNode buildDoc (String key, String value, String op) {
-            ObjectNode node = JsonUtils.createObjectNode();
-            node.put("@type", "koral:doc");
-            // eq.equals(EQ.EQUAL) ? "match:eq" : "match:ne"
-            node.put("match", op);
-            node.put("key", key);
-            node.put("value", value);
-
-            return node;
-        }
-
-
-        public static JsonNode buildDocGroup () {
-            ObjectNode node = JsonUtils.createObjectNode();
-
-            return node;
-        }
-
-    }
-
-}
diff --git a/src/main/java/de/ids_mannheim/korap/utils/StringUtils.java b/src/main/java/de/ids_mannheim/korap/utils/StringUtils.java
index 7cd7b56..e5ab428 100644
--- a/src/main/java/de/ids_mannheim/korap/utils/StringUtils.java
+++ b/src/main/java/de/ids_mannheim/korap/utils/StringUtils.java
@@ -136,35 +136,4 @@
         return StringEscapeUtils.unescapeHtml(value);
     }
 
-
-    /**
-     * constructs a lucene query from query string and corpus
-     * parameters as set
-     * 
-     * @param query
-     * @param corpusIDs
-     * @return
-     */
-    public static String queryBuilder (String query,
-            Collection<String> corpusIDs) {
-        String completeQuery; // holds original query and corpus
-        // selection
-        /**
-         * find documents with metadataquery TODO: does not intercept
-         * with
-         * parameters foundries and corpusIDs
-         */
-
-        /* add corpus ids to corpus query */
-        StringBuilder corpusQuery = new StringBuilder("corpus:/(");
-        for (String corpusId : corpusIDs) {
-            corpusQuery.append(corpusId + "|");
-        }
-        corpusQuery.deleteCharAt(corpusQuery.length() - 1);
-        corpusQuery.append(")/");
-        completeQuery = "(" + query + ") AND " + corpusQuery.toString();
-        jlog.debug("Searching documents matching '" + completeQuery + "'.");
-        return completeQuery;
-    }
-
 }
diff --git a/src/main/java/de/ids_mannheim/korap/web/filter/PiwikFilter.java b/src/main/java/de/ids_mannheim/korap/web/filter/PiwikFilter.java
index fc32b67..26cde36 100644
--- a/src/main/java/de/ids_mannheim/korap/web/filter/PiwikFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/web/filter/PiwikFilter.java
@@ -10,6 +10,7 @@
 import com.sun.jersey.spi.container.ContainerRequestFilter;
 import com.sun.jersey.spi.container.ContainerResponseFilter;
 import com.sun.jersey.spi.container.ResourceFilter;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.config.BeansFactory;
 import de.ids_mannheim.korap.exceptions.KustvaktException;
 import de.ids_mannheim.korap.interfaces.AuthenticationManagerIface;
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/CollectionLoader.java b/src/main/java/de/ids_mannheim/korap/web/service/CollectionLoader.java
index a88cb1b..be4593f 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/CollectionLoader.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/CollectionLoader.java
@@ -9,9 +9,9 @@
 import de.ids_mannheim.korap.security.ac.PolicyBuilder;
 import de.ids_mannheim.korap.security.ac.ResourceFinder;
 import de.ids_mannheim.korap.security.ac.SecurityManager;
-import de.ids_mannheim.korap.user.Attributes;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.user.User;
-import de.ids_mannheim.korap.utils.CollectionQueryBuilder3;
+import de.ids_mannheim.korap.utils.KoralCollectionQueryBuilder;
 import de.ids_mannheim.korap.utils.JsonUtils;
 
 /**
@@ -28,8 +28,8 @@
         User user = User.UserFactory
                 .toUser(KustvaktConfiguration.KUSTVAKT_USER);
 
-        CollectionQueryBuilder3 bui = new CollectionQueryBuilder3();
-        bui.addQuery("creationDate since 1775");
+        KoralCollectionQueryBuilder bui = new KoralCollectionQueryBuilder();
+        bui.with("creationDate since 1775");
 
         VirtualCollection c1 = new VirtualCollection();
         c1.setName("Weimarer Werke");
@@ -37,16 +37,16 @@
 
         c1.setDescription("Goethe-Werke in Weimar (seit 1775)");
 
-        bui = new CollectionQueryBuilder3();
-        bui.addQuery("textType = Aphorismus");
+        bui = new KoralCollectionQueryBuilder();
+        bui.with("textType = Aphorismus");
 
         VirtualCollection c2 = new VirtualCollection();
         c2.setName("Aphorismen");
         c2.addField(Attributes.QUERY, bui.toJSON());
         c2.setDescription("Aphorismentexte Goethes");
 
-        bui = new CollectionQueryBuilder3();
-        bui.addQuery("title ~ \"Werther\"");
+        bui = new KoralCollectionQueryBuilder();
+        bui.with("title ~ \"Werther\"");
 
         VirtualCollection c3 = new VirtualCollection();
         c3.setName("Werther");
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/full/AuthService.java b/src/main/java/de/ids_mannheim/korap/web/service/full/AuthService.java
index 23852b1..6d2e309 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/full/AuthService.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/full/AuthService.java
@@ -2,6 +2,7 @@
 
 import com.sun.jersey.spi.container.ContainerRequest;
 import com.sun.jersey.spi.container.ResourceFilters;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.config.BeansFactory;
 import de.ids_mannheim.korap.exceptions.KustvaktException;
 import de.ids_mannheim.korap.exceptions.StatusCodes;
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java b/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java
index 73e3047..0bfab1e 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java
@@ -3,6 +3,7 @@
 import com.fasterxml.jackson.databind.JsonNode;
 import com.sun.jersey.core.util.MultivaluedMapImpl;
 import com.sun.jersey.spi.container.ResourceFilters;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.config.BeansFactory;
 import de.ids_mannheim.korap.config.KustvaktConfiguration;
 import de.ids_mannheim.korap.exceptions.EmptyResultException;
@@ -92,6 +93,8 @@
         Class cl_type = ResourceFactory.getResourceClass(type);
         if (cl_type == null) {
             //todo return bad request response
+            throw KustvaktResponseHandler.throwit(StatusCodes.REQUEST_INVALID,
+                    "Resource type not available!", "");
         }
 
         try {
@@ -105,25 +108,8 @@
         }
 
         Set values = new HashSet();
-        for (KustvaktResource resource : resources) {
-            // fixme: remove -- to costly
-            //            if (cl_type.equals(VirtualCollection.class)) {
-            //                VirtualCollection c = (VirtualCollection) resource;
-            //                CollectionQueryBuilder3 query = new CollectionQueryBuilder3();
-            //                query.setBaseQuery(c.getQuery());
-            //                String stats = searchKrill.getStatistics(query.toJSON());
-            //
-            //                c.setStats(JsonUtils.readSimple(stats, Map.class));
-            //
-            //            }else if (cl_type.equals(Corpus.class)) {
-            //                Corpus c = (Corpus) resource;
-            //                CollectionQueryBuilder3 query = new CollectionQueryBuilder3();
-            //                query.addQuery("corpusID=" + c.getPersistentID());
-            //                String stats = searchKrill.getStatistics(query.toJSON());
-            //                c.setStats(JsonUtils.readSimple(stats, Map.class));
-            //            }
+        for (KustvaktResource resource : resources)
             values.add(resource.toMap());
-        }
         return Response.ok(JsonUtils.toJSON(values)).build();
     }
 
@@ -166,16 +152,6 @@
         catch (KustvaktException e) {
             throw KustvaktResponseHandler.throwit(e);
         }
-        CollectionQueryBuilder3 query = new CollectionQueryBuilder3();
-        if (cl_type.equals(VirtualCollection.class)) {
-            VirtualCollection c = (VirtualCollection) resource;
-            query.setBaseQuery((String) c.getData());
-        }
-        else if (cl_type.equals(Corpus.class)) {
-            Corpus c = (Corpus) resource;
-            query.addQuery("corpusID=" + c.getPersistentID());
-        }
-
         return Response.ok(JsonUtils.toJSON(resource.toMap())).build();
     }
 
@@ -191,7 +167,7 @@
     //            @QueryParam("paths") Boolean wPaths) {
     //        TokenContext tokenContext = (TokenContext) ctx.getUserPrincipal();
     //        ColloQuery.ColloQueryBuilder builder;
-    //        CollectionQueryBuilder3 cquery = new CollectionQueryBuilder3();
+    //        KoralCollectionQueryBuilder cquery = new KoralCollectionQueryBuilder();
     //        String result;
     //        try {
     //            User user = controller.getUser(tokenContext.getUsername());
@@ -238,7 +214,7 @@
     //        TokenContext tokenContext = (TokenContext) ctx.getUserPrincipal();
     //        String result;
     //        try {
-    //            CollectionQueryBuilder3 cquery = new CollectionQueryBuilder3();
+    //            KoralCollectionQueryBuilder cquery = new KoralCollectionQueryBuilder();
     //            try {
     //                User user = controller.getUser(tokenContext.getUsername());
     //
@@ -312,30 +288,16 @@
             @QueryParam("ref") String reference, @QueryParam("cq") String cq) {
         TokenContext ctx = (TokenContext) securityContext.getUserPrincipal();
         QuerySerializer ss;
-        CollectionQueryBuilder3 cquery = new CollectionQueryBuilder3();
-        if (cq != null)
-            cquery.setBaseQuery(cq);
 
         User user;
         try {
             user = controller.getUser(ctx.getUsername());
-            Set<Corpus> resources = new HashSet<>();
-
-            if (User.UserFactory.isDemo(ctx.getUsername()))
-                resources = ResourceFinder.searchPublic(Corpus.class);
-            else
-                resources = ResourceFinder.search(user, Corpus.class);
-            System.out.println("RESOURCES FOUND " + resources);
-
-            for (KustvaktResource corpus : resources)
-                cquery.addQuery("corpusID=" + corpus.getPersistentID());
         }
         catch (KustvaktException e) {
             throw KustvaktResponseHandler.throwit(e);
         }
 
         ss = new QuerySerializer().setQuery(q, ql, v);
-        ss.setCollection(cquery.toJSON());
 
         MetaQueryBuilder meta = new MetaQueryBuilder();
         if (pageIndex != null)
@@ -369,7 +331,7 @@
      * @return
      */
 
-    //todo: does cq have any sensable worth here?
+    //todo: does cq have any sensible worth here?
     @TRACE
     @Path("{type}/{id}/search")
     public Response buildQuery (@Context Locale locale,
@@ -385,36 +347,8 @@
         TokenContext ctx = (TokenContext) securityContext.getUserPrincipal();
         type = StringUtils.normalize(type);
         id = StringUtils.decodeHTML(id);
-        QuerySerializer ss;
-        //fixme: not used anywhere!
-        CollectionQueryBuilder3 cquery = new CollectionQueryBuilder3();
-        if (cq != null)
-            cquery.setBaseQuery(cq);
 
-        try {
-            User user = controller.getUser(ctx.getUsername());
-
-            //todo: instead of throwing exception, build notification and rewrites into result query
-            KustvaktResource resource;
-            if (StringUtils.isInteger(id))
-                resource = this.resourceHandler.findbyIntId(
-                        Integer.valueOf(id), user);
-            else
-                resource = this.resourceHandler.findbyStrId(id, user,
-                        ResourceFactory.getResourceClass(type));
-
-            if (resource instanceof VirtualCollection)
-                cquery.addQuery((String) resource.getData());
-            else if (resource instanceof Corpus)
-                cquery.addQuery("corpusID=" + resource.getPersistentID());
-
-        }
-        catch (KustvaktException e) {
-            jlog.error("Exception encountered!", e);
-            //throw KustvaktResponseHandler.throwit(e);
-        }
-
-        ss = new QuerySerializer().setQuery(q, ql, v);
+        QuerySerializer ss = new QuerySerializer().setQuery(q, ql, v);
 
         MetaQueryBuilder meta = new MetaQueryBuilder();
         if (pageIndex != null)
@@ -429,6 +363,35 @@
             meta.addEntry("cutOff", cutoff);
 
         ss.setMeta(meta.raw());
+        if (cq != null)
+            ss.setCollection(cq);
+
+        KoralCollectionQueryBuilder cquery = new KoralCollectionQueryBuilder();
+        cquery.setBaseQuery(ss.toJSON());
+
+        try {
+            User user = controller.getUser(ctx.getUsername());
+
+            //todo: instead of throwing exception, build notification and rewrites into result query
+            KustvaktResource resource;
+            if (StringUtils.isInteger(id))
+                resource = this.resourceHandler.findbyIntId(
+                        Integer.valueOf(id), user);
+            else
+                resource = this.resourceHandler.findbyStrId(id, user,
+                        ResourceFactory.getResourceClass(type));
+
+            if (resource instanceof VirtualCollection)
+                cquery.with((String) resource.getData());
+            else if (resource instanceof Corpus)
+                cquery.with(Attributes.CORPUS_SIGLE + resource.getPersistentID());
+
+        }
+        catch (KustvaktException e) {
+            jlog.error("Exception encountered!", e);
+            //throw KustvaktResponseHandler.throwit(e);
+        }
+
 
         // todo: policy parsing before return
         return Response.ok(ss.toJSON()).build();
@@ -441,8 +404,6 @@
             @Context Locale locale, @QueryParam("engine") String engine,
             String jsonld) {
         TokenContext ctx = (TokenContext) context.getUserPrincipal();
-        //        KustvaktConfiguration.BACKENDS eng = KustvaktConfiguration
-        //                .chooseBackend(engine);
 
         // todo: should be possible to add the meta part to the query serialization
         try {
@@ -473,15 +434,12 @@
             @QueryParam("cq") String cq, @QueryParam("engine") String engine) {
         TokenContext context = (TokenContext) securityContext
                 .getUserPrincipal();
-        CollectionQueryBuilder3 cquery = new CollectionQueryBuilder3();
+        KoralCollectionQueryBuilder cquery = new KoralCollectionQueryBuilder();
         KustvaktConfiguration.BACKENDS eng = this.config.chooseBackend(engine);
         User user;
         // todo: not added to query!!
         try {
             user = controller.getUser(context.getUsername());
-            Set<Corpus> resources = ResourceFinder.search(user, Corpus.class);
-            for (KustvaktResource resource : resources)
-                cquery.addQuery("corpusID=" + resource.getPersistentID());
         }
         catch (KustvaktException e) {
             jlog.error("Exception encountered!", e);
@@ -492,8 +450,9 @@
         serializer.setQuery(q, ql, v);
 
         // todo: parse for security reasons
-        if (cq != null)
-            serializer.setCollection(cq);
+        // todo: remove cq parameter
+        // if (cq != null)
+        //    serializer.setCollection(cq);
 
         MetaQueryBuilder meta = new MetaQueryBuilder();
         meta.addEntry("startIndex", pageIndex);
@@ -576,7 +535,9 @@
             if (!raw) {
                 QuerySerializer s = new QuerySerializer();
                 s.setQuery(query, ql, v);
-                CollectionQueryBuilder3 builder = new CollectionQueryBuilder3();
+
+                // fixme: be replaced by public collection rewrite
+                KoralCollectionQueryBuilder builder = new KoralCollectionQueryBuilder();
 
                 KustvaktResource resource;
                 if (StringUtils.isInteger(id))
@@ -589,7 +550,7 @@
                 if (resource instanceof VirtualCollection)
                     builder.setBaseQuery((String) resource.getData());
                 else if (resource instanceof Corpus)
-                    builder.addQuery("corpusID=" + resource.getPersistentID());
+                    builder.with(Attributes.CORPUS_SIGLE+ resource.getPersistentID());
                 else
                     throw KustvaktResponseHandler.throwit(
                             StatusCodes.ILLEGAL_ARGUMENT,
@@ -656,8 +617,8 @@
     @Path("stats")
     public Response getStats (@Context SecurityContext context,
             @Context Locale locale, String json) {
-        CollectionQueryBuilder3 builder = new CollectionQueryBuilder3();
-        builder.addQuery(json);
+        KoralCollectionQueryBuilder builder = new KoralCollectionQueryBuilder();
+        builder.with(json);
         String stats = searchKrill.getStatistics(builder.toJSON());
 
         if (stats.contains("-1"))
@@ -702,16 +663,19 @@
                         ResourceFactory.getResourceClass(type));
 
             //todo ?!
-            CollectionQueryBuilder3 query = new CollectionQueryBuilder3();
+            KoralCollectionQueryBuilder query = new KoralCollectionQueryBuilder();
             if (resource instanceof VirtualCollection) {
                 query.setBaseQuery(resource.getData());
             }
             else if (resource instanceof Corpus) {
-                query.addQuery("corpusID=" + resource.getName());
+                query.with("corpusID=" + resource.getName());
             }
 
+            String res = query.toJSON();
+            jlog.info("BEFORE REWRITE " + res);
             // rewrite process
-            String qstr = processor.preProcess(query.toJSON(), user);
+            String qstr = processor.preProcess(res, user);
+            jlog.info("AFTER REWRITE " + qstr);
             return Response.ok(searchKrill.getStatistics(qstr)).build();
         }
         catch (KustvaktException e) {
@@ -744,7 +708,7 @@
         VirtualCollection tmp = resourceHandler.getCache(cache.getId(),
                 VirtualCollection.class);
         if (tmp == null) {
-            CollectionQueryBuilder3 cquery = new CollectionQueryBuilder3()
+            KoralCollectionQueryBuilder cquery = new KoralCollectionQueryBuilder()
                     .setBaseQuery((String) cache.getData());
             String query = this.processor.preProcess((String) cache.getData(),
                     user);
@@ -842,7 +806,7 @@
                 // todo: throw exception response for no resource to save!
                 return null;
 
-            CollectionQueryBuilder3 cquery = new CollectionQueryBuilder3();
+            KoralCollectionQueryBuilder cquery = new KoralCollectionQueryBuilder();
             cquery.setBaseQuery(base);
 
             cachetmp = ResourceFactory.getCachedCollection(cquery.toJSON());
@@ -915,10 +879,10 @@
             VirtualCollection cachetmp, collection;
             // todo: ??
             Object read = JsonUtils.readTree(query);
-            CollectionQueryBuilder3 cquery = new CollectionQueryBuilder3();
+            KoralCollectionQueryBuilder cquery = new KoralCollectionQueryBuilder();
             if (reference != null && !reference.equals("null")) {
                 try {
-                    cquery.addQuery((String) resourceHandler.findbyStrId(
+                    cquery.with((String) resourceHandler.findbyStrId(
                             reference, user, VirtualCollection.class).getData());
                 }
                 catch (KustvaktException e) {
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/full/UserService.java b/src/main/java/de/ids_mannheim/korap/web/service/full/UserService.java
index 9273171..5aa25c9 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/full/UserService.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/full/UserService.java
@@ -4,6 +4,7 @@
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.sun.jersey.spi.container.ContainerRequest;
 import com.sun.jersey.spi.container.ResourceFilters;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.config.BeansFactory;
 import de.ids_mannheim.korap.config.Scopes;
 import de.ids_mannheim.korap.config.URIParam;
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/light/LightService.java b/src/main/java/de/ids_mannheim/korap/web/service/light/LightService.java
index 1d7e556..9c5a74a 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/light/LightService.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/light/LightService.java
@@ -10,7 +10,7 @@
 import de.ids_mannheim.korap.query.serialize.QuerySerializer;
 import de.ids_mannheim.korap.resource.rewrite.FoundryInject;
 import de.ids_mannheim.korap.resource.rewrite.RewriteHandler;
-import de.ids_mannheim.korap.utils.CollectionQueryBuilder3;
+import de.ids_mannheim.korap.utils.KoralCollectionQueryBuilder;
 import de.ids_mannheim.korap.utils.KustvaktLogger;
 import de.ids_mannheim.korap.web.ClientsHandler;
 import de.ids_mannheim.korap.web.SearchKrill;
@@ -89,7 +89,6 @@
             @QueryParam("count") Integer pageLength,
             @QueryParam("offset") Integer pageIndex,
             @QueryParam("page") Integer startPage,
-            // fixme: remove cq from light service
             @QueryParam("cq") String cq) {
         QuerySerializer ss = new QuerySerializer().setQuery(q, ql, v);
 
@@ -251,8 +250,8 @@
     @POST
     @Path("stats")
     public Response getStats (String json) {
-        CollectionQueryBuilder3 builder = new CollectionQueryBuilder3();
-        builder.addQuery(json);
+        KoralCollectionQueryBuilder builder = new KoralCollectionQueryBuilder();
+        builder.with(json);
 
         // todo: policy override in extension!
         String stats = searchKrill.getStatistics(builder.toJSON());
diff --git a/src/test/java/CollectionQueryBuilderTest.java b/src/test/java/CollectionQueryBuilderTest.java
index 0840e20..38a5ac4 100644
--- a/src/test/java/CollectionQueryBuilderTest.java
+++ b/src/test/java/CollectionQueryBuilderTest.java
@@ -1,11 +1,11 @@
 import com.fasterxml.jackson.databind.JsonNode;
 import de.ids_mannheim.korap.query.serialize.QuerySerializer;
-import de.ids_mannheim.korap.utils.CollectionQueryBuilder3;
+import de.ids_mannheim.korap.utils.KoralCollectionQueryBuilder;
 import de.ids_mannheim.korap.utils.JsonUtils;
-import org.junit.Assert;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 
 /**
@@ -16,28 +16,28 @@
 
     @Test
     public void testsimpleAdd () {
-        CollectionQueryBuilder3 b = new CollectionQueryBuilder3();
-        b.addQuery("corpusID=WPD");
+        KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder();
+        b.with("corpusSigle=WPD");
 
         JsonNode node = JsonUtils.readTree(b.toJSON());
 
         assertNotNull(node);
         assertEquals("koral:doc", node.at("/collection/@type").asText());
-        assertEquals("corpusID", node.at("/collection/key").asText());
+        assertEquals("corpusSigle", node.at("/collection/key").asText());
     }
 
 
     @Test
     public void testSimpleConjunction () {
-        CollectionQueryBuilder3 b = new CollectionQueryBuilder3();
-        b.addQuery("corpusID=WPD & textClass=freizeit");
+        KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder();
+        b.with("corpusSigle=WPD & textClass=freizeit");
         JsonNode node = JsonUtils.readTree(b.toJSON());
 
         assertNotNull(node);
         assertEquals("koral:docGroup", node.at("/collection/@type").asText());
         assertEquals("operation:and", node.at("/collection/operation").asText());
 
-        assertEquals("corpusID", node.at("/collection/operands/0/key").asText());
+        assertEquals("corpusSigle", node.at("/collection/operands/0/key").asText());
         assertEquals("textClass", node.at("/collection/operands/1/key")
                 .asText());
     }
@@ -45,17 +45,14 @@
 
     @Test
     public void testSimpleDisjunction () {
-        CollectionQueryBuilder3 b = new CollectionQueryBuilder3();
-        b.addQuery("corpusID=WPD | textClass=freizeit");
+        KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder();
+        b.with("corpusSigle=WPD | textClass=freizeit");
         JsonNode node = JsonUtils.readTree(b.toJSON());
 
-        System.out.println("_____________________________________________");
-        System.out.println(node);
-
-        assert node != null;
+        assertNotNull(node);
         assert node.at("/collection/operation").asText().equals("operation:or");
         assert node.at("/collection/operands/0/key").asText()
-                .equals("corpusID");
+                .equals("corpusSigle");
         assert node.at("/collection/operands/1/key").asText()
                 .equals("textClass");
     }
@@ -63,17 +60,14 @@
 
     @Test
     public void testComplexSubQuery () {
-        CollectionQueryBuilder3 b = new CollectionQueryBuilder3();
-        b.addQuery("(corpusID=WPD) | (textClass=freizeit & corpusID=WPD)");
+        KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder();
+        b.with("(corpusSigle=WPD) | (textClass=freizeit & corpusSigle=BRZ13)");
         JsonNode node = JsonUtils.readTree(b.toJSON());
 
-        System.out
-                .println("_____________________________________________ COMPLEX");
-        System.out.println(node);
-        assert node != null;
+        assertNotNull(node);
         assert node.at("/collection/operation").asText().equals("operation:or");
         assert node.at("/collection/operands/0/key").asText()
-                .equals("corpusID");
+                .equals("corpusSigle");
         assert node.at("/collection/operands/1/@type").asText()
                 .equals("koral:docGroup");
 
@@ -82,60 +76,128 @@
 
     @Test
     public void testAddResourceQueryAfter () {
-        CollectionQueryBuilder3 b = new CollectionQueryBuilder3();
-        b.addQuery("(corpusID=ADF) | (textClass=freizeit & corpusID=WPD)");
+        KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder();
+        b.with("(textClass=politik & title=\"random title\") | textClass=wissenschaft");
 
-        CollectionQueryBuilder3 c = new CollectionQueryBuilder3();
+        KoralCollectionQueryBuilder c = new KoralCollectionQueryBuilder();
         c.setBaseQuery(b.toJSON());
-        c.addQuery("textClass=wissenschaft");
+        c.with("corpusSigle=WPD");
 
         JsonNode node = JsonUtils.readTree(c.toJSON());
 
-        assert node != null;
-        assert node.at("/collection/operands/2/@type").asText()
-                .equals("koral:doc");
-        assert node.at("/collection/operands/2/value").asText()
-                .equals("wissenschaft");
+        assertNotNull(node);
+        assertEquals("koral:doc", node.at("/collection/operands/0/@type")
+                .asText());
+        assertEquals("WPD", node.at("/collection/operands/0/value").asText());
+        assertEquals(2, node.at("/collection/operands").size());
     }
 
 
     @Test
     public void testAddComplexResourceQueryAfter () {
-        CollectionQueryBuilder3 b = new CollectionQueryBuilder3();
-        b.addQuery("(corpusID=ADF) | (textClass=freizeit & corpusID=WPD)");
+        KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder();
+        b.with("(title=\"random title\") | (textClass=wissenschaft)");
 
-        CollectionQueryBuilder3 c = new CollectionQueryBuilder3();
+        KoralCollectionQueryBuilder c = new KoralCollectionQueryBuilder();
         c.setBaseQuery(b.toJSON());
-        c.addQuery("(textClass=politik & corpusID=AZPS)");
+        c.with("(corpusSigle=BRZ13 | corpusSigle=AZPS)");
 
         JsonNode node = JsonUtils.readTree(c.toJSON());
-
-        assert node != null;
-        assert node.at("/collection/operands/2/@type").asText()
-                .equals("koral:docGroup");
-        assert node.at("/collection/operands/2/operands/0/value").asText()
-                .equals("politik");
-        assert node.at("/collection/operands/2/operands/1/value").asText()
-                .equals("AZPS");
-
+        assertNotNull(node);
+        assertEquals("koral:docGroup", node.at("/collection/operands/0/@type")
+                .asText());
+        assertEquals("koral:docGroup", node.at("/collection/operands/1/@type")
+                .asText());
+        assertEquals("BRZ13", node
+                .at("/collection/operands/0/operands/0/value").asText());
+        assertEquals("AZPS", node.at("/collection/operands/0/operands/1/value")
+                .asText());
+        assertEquals("random title",
+                node.at("/collection/operands/1/operands/0/value").asText());
+        assertEquals("wissenschaft",
+                node.at("/collection/operands/1/operands/1/value").asText());
     }
 
 
     @Test
-    public void buildQuery () {
+    public void testBuildQuery () {
+        String coll = "corpusSigle=WPD";
         String query = "[base=Haus]";
-        QuerySerializer s = new QuerySerializer();
-        s.setQuery(query, "poliqarp");
-        CollectionQueryBuilder3 b = new CollectionQueryBuilder3();
-        b.addQuery("corpusID=WPD");
-        s.setCollection("corpusID=WPD");
+        QuerySerializer check = new QuerySerializer();
+        check.setQuery(query, "poliqarp");
+        check.setCollection(coll);
 
-        System.out.println("QUERY " + s.toJSON());
+        KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder();
+        b.setBaseQuery(check.toJSON());
+        b.with("textClass=freizeit");
+
+        JsonNode res = (JsonNode) b.rebaseCollection();
+        assertNotNull(res);
+        assertEquals("koral:docGroup", res.at("/collection/@type").asText());
+        assertEquals("operation:and", res.at("/collection/operation").asText());
+        assertEquals("koral:doc", res.at("/collection/operands/0/@type")
+                .asText());
+        assertEquals("freizeit", res.at("/collection/operands/0/value")
+                .asText());
+        assertEquals("textClass", res.at("/collection/operands/0/key").asText());
+
+        assertEquals("koral:doc", res.at("/collection/operands/1/@type")
+                .asText());
+        assertEquals("WPD", res.at("/collection/operands/1/value").asText());
+        assertEquals("corpusSigle", res.at("/collection/operands/1/key").asText());
+
+        // check also that query is still there
+        assertEquals("koral:token", res.at("/query/@type").asText());
+        assertEquals("koral:term", res.at("/query/wrap/@type").asText());
+        assertEquals("Haus", res.at("/query/wrap/key").asText());
+        assertEquals("lemma", res.at("/query/wrap/layer").asText());
     }
 
 
     @Test
     public void testBaseQueryBuild () {
+        KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder();
+        b.with("(corpusSigle=ADF) | (textClass=freizeit & corpusSigle=WPD)");
+
+        KoralCollectionQueryBuilder c = new KoralCollectionQueryBuilder();
+        c.setBaseQuery(b.toJSON());
+
+        c.with("corpusSigle=BRZ13");
+        JsonNode base = (JsonNode) c.rebaseCollection();
+        assertNotNull(base);
+        assertEquals(base.at("/collection/@type").asText(), "koral:docGroup");
+        assertEquals(base.at("/collection/operands/0/@type").asText(),
+                "koral:doc");
+        assertEquals(base.at("/collection/operands/0/value").asText(), "BRZ13");
+        assertEquals(base.at("/collection/operands/1/@type").asText(),
+                "koral:docGroup");
+        assertEquals(base.at("/collection/operands/1/operands").size(), 2);
+    }
+
+    @Test
+    public void testNodeMergeWithBase() {
+        String coll = "corpusSigle=WPD";
+        String query = "[base=Haus]";
+        QuerySerializer check = new QuerySerializer();
+        check.setQuery(query, "poliqarp");
+        check.setCollection(coll);
+
+        KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder();
+        b.setBaseQuery(check.toJSON());
+
+        KoralCollectionQueryBuilder test = new KoralCollectionQueryBuilder();
+        test.with("textClass=wissenschaft | textClass=politik");
+        JsonNode node = (JsonNode) test.rebaseCollection();
+        node = b.mergeWith(node);
+        assertNotNull(node);
+        assertEquals("koral:docGroup", node.at("/collection/@type").asText());
+        assertEquals("operation:and", node.at("/collection/operation").asText());
+        assertEquals(2, node.at("/collection/operands").size());
+    }
+
+
+    @Test
+    public void testStoredCollectionBaseQueryBuild () {
 
     }
 
diff --git a/src/test/java/de/ids_mannheim/korap/config/ConfigTest.java b/src/test/java/de/ids_mannheim/korap/config/ConfigTest.java
index fe2201f..c11b7e3 100644
--- a/src/test/java/de/ids_mannheim/korap/config/ConfigTest.java
+++ b/src/test/java/de/ids_mannheim/korap/config/ConfigTest.java
@@ -1,7 +1,6 @@
 package de.ids_mannheim.korap.config;
 
 import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.user.Attributes;
 import de.ids_mannheim.korap.utils.ServiceInfo;
 import de.ids_mannheim.korap.utils.TimeUtils;
 import de.ids_mannheim.korap.web.service.BootableBeanInterface;
diff --git a/src/test/java/de/ids_mannheim/korap/config/TestHelper.java b/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
index 0746293..2c36b66 100644
--- a/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
+++ b/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
@@ -12,7 +12,6 @@
 import de.ids_mannheim.korap.security.auth.APIAuthentication;
 import de.ids_mannheim.korap.security.auth.BasicHttpAuth;
 import de.ids_mannheim.korap.security.auth.KustvaktAuthenticationManager;
-import de.ids_mannheim.korap.user.Attributes;
 import de.ids_mannheim.korap.user.User;
 import de.ids_mannheim.korap.web.service.BootableBeanInterface;
 import org.apache.commons.dbcp2.BasicDataSource;
diff --git a/src/test/java/de/ids_mannheim/korap/resource/rewrite/CollectionRewriteTest.java b/src/test/java/de/ids_mannheim/korap/resource/rewrite/CollectionRewriteTest.java
index 0c7035b..4e4aa3f 100644
--- a/src/test/java/de/ids_mannheim/korap/resource/rewrite/CollectionRewriteTest.java
+++ b/src/test/java/de/ids_mannheim/korap/resource/rewrite/CollectionRewriteTest.java
@@ -5,11 +5,15 @@
 import de.ids_mannheim.korap.config.KustvaktConfiguration;
 import de.ids_mannheim.korap.exceptions.KustvaktException;
 import de.ids_mannheim.korap.query.serialize.QuerySerializer;
+import de.ids_mannheim.korap.resources.Corpus;
+import de.ids_mannheim.korap.resources.KustvaktResource;
+import de.ids_mannheim.korap.security.ac.ResourceFinder;
 import de.ids_mannheim.korap.user.User;
 import de.ids_mannheim.korap.utils.JsonUtils;
 import org.junit.Assert;
 import org.junit.Test;
 
+import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -29,6 +33,7 @@
 
     @Override
     public void initMethod () throws KustvaktException {
+        helper().runBootInterfaces();
         config = helper().getContext().getConfiguration();
     }
 
@@ -181,5 +186,45 @@
     }
 
 
+    @Test
+    public void testPublicCollectionRewriteEmptyAdd () throws KustvaktException {
+        RewriteHandler handler = new RewriteHandler();
+        handler.insertBeans(helper().getContext());
+        handler.add(PublicCollection.class);
+
+        QuerySerializer s = new QuerySerializer();
+        s.setQuery(simple_add_query, "poliqarp");
+        String org = s.toJSON();
+        JsonNode node = JsonUtils.readTree(handler.preProcess(org,
+                User.UserFactory.getUser("test_user")));
+        assertNotNull(node);
+        System.out.println("EMPTY " + node);
+    }
+
+
+    @Test
+    public void testPublicCollectionRewriteNonEmptyAdd ()
+            throws KustvaktException {
+        RewriteHandler handler = new RewriteHandler();
+        handler.insertBeans(helper().getContext());
+        handler.add(PublicCollection.class);
+
+        try {
+            QuerySerializer s = new QuerySerializer();
+            s.setQuery(simple_add_query, "poliqarp");
+            s.setCollection("(docSigle=WPD_AAA & textClass=wissenschaft)");
+            String org = s.toJSON();
+            JsonNode node = JsonUtils.readTree(handler.preProcess(org,
+                    User.UserFactory.getUser("test_user")));
+            assertNotNull(node);
+            System.out.println("NON EMPTY " + node);
+            Set<Corpus> resourceSet = ResourceFinder.searchPublic(Corpus.class);
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+
 
 }
diff --git a/src/test/java/de/ids_mannheim/korap/resource/rewrite/FoundryRewriteTest.java b/src/test/java/de/ids_mannheim/korap/resource/rewrite/FoundryRewriteTest.java
index cb7d38d..032b9f7 100644
--- a/src/test/java/de/ids_mannheim/korap/resource/rewrite/FoundryRewriteTest.java
+++ b/src/test/java/de/ids_mannheim/korap/resource/rewrite/FoundryRewriteTest.java
@@ -9,7 +9,7 @@
 import de.ids_mannheim.korap.interfaces.db.UserDataDbIface;
 import de.ids_mannheim.korap.query.serialize.QuerySerializer;
 import de.ids_mannheim.korap.resource.LayerMapper;
-import de.ids_mannheim.korap.user.Attributes;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.user.User;
 import de.ids_mannheim.korap.user.UserSettings;
 import de.ids_mannheim.korap.utils.JsonUtils;
diff --git a/src/test/java/de/ids_mannheim/korap/resource/rewrite/PostRewriteTest.java b/src/test/java/de/ids_mannheim/korap/resource/rewrite/PostRewriteTest.java
index 91ee4e0..78db747 100644
--- a/src/test/java/de/ids_mannheim/korap/resource/rewrite/PostRewriteTest.java
+++ b/src/test/java/de/ids_mannheim/korap/resource/rewrite/PostRewriteTest.java
@@ -16,7 +16,6 @@
  * @author hanl
  * @date 12/11/2015
  */
-//fixme: tests only work with singleconnection data sources
 // todo: logging!
 public class PostRewriteTest extends BeanConfigTest {
 
diff --git a/src/test/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandlerTest.java b/src/test/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandlerTest.java
index 5eea4e2..070e0bb 100644
--- a/src/test/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandlerTest.java
+++ b/src/test/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandlerTest.java
@@ -6,7 +6,7 @@
 import de.ids_mannheim.korap.exceptions.KustvaktException;
 import de.ids_mannheim.korap.interfaces.db.UserDataDbIface;
 import de.ids_mannheim.korap.query.serialize.QuerySerializer;
-import de.ids_mannheim.korap.user.Attributes;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.user.UserSettings;
 import de.ids_mannheim.korap.utils.JsonUtils;
 import org.junit.Test;
diff --git a/src/test/java/de/ids_mannheim/korap/security/PolicyDaoTest.java b/src/test/java/de/ids_mannheim/korap/security/PolicyDaoTest.java
index 404b86a..8c2a00d 100644
--- a/src/test/java/de/ids_mannheim/korap/security/PolicyDaoTest.java
+++ b/src/test/java/de/ids_mannheim/korap/security/PolicyDaoTest.java
@@ -8,7 +8,7 @@
 import de.ids_mannheim.korap.resources.Permissions;
 import de.ids_mannheim.korap.resources.VirtualCollection;
 import de.ids_mannheim.korap.security.ac.PolicyBuilder;
-import de.ids_mannheim.korap.user.Attributes;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.user.User;
 import edu.emory.mathcs.backport.java.util.Arrays;
 import org.junit.Ignore;
diff --git a/src/test/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManagerTest.java b/src/test/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManagerTest.java
index 973087b..2c0d83e 100644
--- a/src/test/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManagerTest.java
+++ b/src/test/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManagerTest.java
@@ -1,5 +1,6 @@
 package de.ids_mannheim.korap.security.auth;
 
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.config.BeanConfigTest;
 import de.ids_mannheim.korap.config.KustvaktBaseDaoInterface;
 import de.ids_mannheim.korap.config.KustvaktConfiguration;
@@ -8,8 +9,6 @@
 import de.ids_mannheim.korap.interfaces.db.EntityHandlerIface;
 import de.ids_mannheim.korap.user.*;
 import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Assert;
 import org.junit.Test;
 
 import static org.junit.Assert.assertNotEquals;
diff --git a/src/test/java/de/ids_mannheim/korap/user/UserdataTest.java b/src/test/java/de/ids_mannheim/korap/user/UserdataTest.java
index 65b93c8..9295cf3 100644
--- a/src/test/java/de/ids_mannheim/korap/user/UserdataTest.java
+++ b/src/test/java/de/ids_mannheim/korap/user/UserdataTest.java
@@ -1,5 +1,6 @@
 package de.ids_mannheim.korap.user;
 
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.config.BeanConfigTest;
 import de.ids_mannheim.korap.config.BeansFactory;
 import de.ids_mannheim.korap.exceptions.KustvaktException;
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/FilterTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/FilterTest.java
index 5392eec..1da69b9 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/full/FilterTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/FilterTest.java
@@ -4,7 +4,7 @@
 import de.ids_mannheim.korap.config.TestHelper;
 import de.ids_mannheim.korap.exceptions.KustvaktException;
 import de.ids_mannheim.korap.security.auth.BasicHttpAuth;
-import de.ids_mannheim.korap.user.Attributes;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.web.service.FastJerseyTest;
 import org.eclipse.jetty.server.Response;
 import org.junit.BeforeClass;
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/OAuth2EndpointTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/OAuth2EndpointTest.java
index 60b7267..a1a5d5f 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/full/OAuth2EndpointTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/OAuth2EndpointTest.java
@@ -5,7 +5,7 @@
 import de.ids_mannheim.korap.config.TestHelper;
 import de.ids_mannheim.korap.exceptions.KustvaktException;
 import de.ids_mannheim.korap.security.auth.BasicHttpAuth;
-import de.ids_mannheim.korap.user.Attributes;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.utils.JsonUtils;
 import de.ids_mannheim.korap.web.service.FastJerseyTest;
 import org.junit.BeforeClass;
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceServiceTest.java
index d9e761c..6cb7700 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceServiceTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceServiceTest.java
@@ -4,17 +4,14 @@
 import com.sun.jersey.api.client.ClientResponse;
 import de.ids_mannheim.korap.exceptions.KustvaktException;
 import de.ids_mannheim.korap.security.auth.BasicHttpAuth;
-import de.ids_mannheim.korap.user.Attributes;
+import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.utils.JsonUtils;
 import de.ids_mannheim.korap.web.service.FastJerseyTest;
-import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Test;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.*;
 
 /**
  * @author hanl
@@ -37,7 +34,6 @@
                 .path("search")
                 .queryParam("q", "[orth=das]")
                 .queryParam("ql", "poliqarp")
-                //                .queryParam("cq", "corpusID=GOE")
                 .header(Attributes.AUTHORIZATION,
                         BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
                 .get(ClientResponse.class);
@@ -98,7 +94,7 @@
         assertNotNull(node);
         int docs = node.path("documents").asInt();
         assertNotEquals(0, docs);
-        Assert.assertTrue(docs < 15);
+        assertTrue(docs < 15);
     }
 
 
@@ -121,6 +117,8 @@
                 .path("corpus/WPD/search").queryParam("q", "[base=Haus]")
                 .queryParam("ql", "poliqarp").queryParam("context", "base/s:s")
                 .method("TRACE", ClientResponse.class);
+        assertEquals(response.getStatus(),
+                ClientResponse.Status.OK.getStatusCode());
         System.out.println("RESPONSE 1 " + response);
         String ent = response.getEntity(String.class);
         System.out.println("Entity 1 " + ent);
@@ -133,6 +131,8 @@
                 .path("search").queryParam("q", "[base=Haus]")
                 .queryParam("ql", "poliqarp").queryParam("context", "sentence")
                 .method("TRACE", ClientResponse.class);
+        assertEquals(response.getStatus(),
+                ClientResponse.Status.OK.getStatusCode());
         String ent = response.getEntity(String.class);
         JsonNode node = JsonUtils.readTree(ent);
         System.out.println("PUBLIC COLLECTION");
@@ -146,6 +146,8 @@
                 .path("search").queryParam("q", "[base=Haus]")
                 .queryParam("ql", "poliqarp").queryParam("context", "sentence")
                 .get(ClientResponse.class);
+        assertEquals(response.getStatus(),
+                ClientResponse.Status.OK.getStatusCode());
         String ent = response.getEntity(String.class);
         JsonNode node = JsonUtils.readTree(ent);
         assertNotNull(node);
@@ -161,6 +163,8 @@
                 .path("search").queryParam("context", "sentence")
                 .queryParam("q", "[pos=ADJA]").queryParam("ql", "poliqarp")
                 .get(ClientResponse.class);
+        assertEquals(response.getStatus(),
+                ClientResponse.Status.OK.getStatusCode());
     }
 
 
@@ -169,6 +173,8 @@
     public void testSerializationCollection () {
         ClientResponse response = resource().path(getAPIVersion()).path("")
                 .get(ClientResponse.class);
+        assertEquals(response.getStatus(),
+                ClientResponse.Status.OK.getStatusCode());
     }
 
 
@@ -178,6 +184,19 @@
     }
 
 
+    @Test
+    public void testGetResources () {
+        ClientResponse response = resource().path(getAPIVersion())
+                .path("corpus").get(ClientResponse.class);
+        assertEquals(response.getStatus(),
+                ClientResponse.Status.OK.getStatusCode());
+        String ent = response.getEntity(String.class);
+        JsonNode node = JsonUtils.readTree(ent);
+        assertNotNull(node);
+        System.out.println("NODE 1 " + node);
+    }
+
+
     @Override
     public void initMethod () throws KustvaktException {
         helper().runBootInterfaces();