resoure service error
diff --git a/src/main/java/de/ids_mannheim/korap/config/AdminSetup.java b/src/main/java/de/ids_mannheim/korap/config/AdminSetup.java
new file mode 100644
index 0000000..5c0a276
--- /dev/null
+++ b/src/main/java/de/ids_mannheim/korap/config/AdminSetup.java
@@ -0,0 +1,64 @@
+package de.ids_mannheim.korap.config;
+
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.interfaces.EncryptionIface;
+
+import java.io.*;
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * Created by hanl on 30.05.16.
+ */
+public class AdminSetup {
+
+    private final String token_hash;
+
+    private static AdminSetup setup;
+
+
+    private AdminSetup (String token_hash) {
+        this.token_hash = token_hash;
+    }
+
+
+    public static AdminSetup getInstance () {
+        if (setup == null)
+            setup = init();
+        return setup;
+    }
+
+
+    public String getHash () {
+        return this.token_hash;
+    }
+
+
+    private static AdminSetup init () {
+        EncryptionIface iface = BeansFactory.getKustvaktContext()
+                .getEncryption();
+        String token = iface.createToken();
+        File store = new File("./admin_token");
+        try {
+            String hash = iface.secureHash(token);
+            AdminSetup setup = new AdminSetup(hash);
+            FileOutputStream out = new FileOutputStream(store);
+            out.write(token.getBytes());
+
+            out.close();
+
+            store.setReadable(true, true);
+            store.setWritable(true, true);
+            store.setExecutable(false);
+            System.out
+                    .println("_______________________________________________");
+            System.out.println("Token created. Please make note of it!");
+            System.out.println("Token: " + token);
+            System.out
+                    .println("_______________________________________________");
+            return setup;
+        }
+        catch (Exception e) {
+            throw new RuntimeException("setup failed! ", e);
+        }
+    }
+}
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 5352435..a657c87 100644
--- a/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
+++ b/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
@@ -69,6 +69,7 @@
     // fixme: should move to base config?!
     private EncryptionIface.Encryption encryption;
     private byte[] sharedSecret;
+    @Deprecated
     private String adminToken;
     private int longTokenTTL;
     private int tokenTTL;
diff --git a/src/main/java/de/ids_mannheim/korap/handlers/DocumentDao.java b/src/main/java/de/ids_mannheim/korap/handlers/DocumentDao.java
index a477d31..3de9412 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/DocumentDao.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/DocumentDao.java
@@ -5,8 +5,10 @@
 import de.ids_mannheim.korap.interfaces.db.PersistenceClient;
 import de.ids_mannheim.korap.interfaces.db.ResourceOperationIface;
 import de.ids_mannheim.korap.resources.Document;
+import de.ids_mannheim.korap.resources.KustvaktResource;
 import de.ids_mannheim.korap.user.User;
 import de.ids_mannheim.korap.utils.BooleanUtils;
+import de.ids_mannheim.korap.utils.StringUtils;
 import edu.emory.mathcs.backport.java.util.Collections;
 import org.springframework.dao.DataAccessException;
 import org.springframework.dao.EmptyResultDataAccessException;
@@ -19,12 +21,12 @@
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Set;
 
 /**
  * @author hanl
  * @date 05/11/2014
  */
-// todo: testing!
 // todo: error handling
 public class DocumentDao implements ResourceOperationIface<Document> {
 
@@ -69,13 +71,15 @@
     }
 
 
-    // document id, consisting of corpus sigle, substring key and document number
+    // todo: search for partial matches if entire document is disabled
+    // document id, consisting of corpus sigle, substring key and text number
     @Override
     public Document findbyId (String id, User user) throws KustvaktException {
         MapSqlParameterSource s = new MapSqlParameterSource();
         s.addValue("id", id);
-        //        strftime('%s', created) as created
-        String sql = "select id, persistent_id, disabled, created from doc_store where persistent_id=:id;";
+        s.addValue("docSigle", StringUtils.getDocSigle(id));
+
+        String sql = "select id, persistent_id, disabled, created from doc_store where persistent_id=:id or persistent_id like :docSigle;";
         try {
             return this.jdbcTemplate.queryForObject(sql, s,
                     new RowMapper<Document>() {
@@ -99,6 +103,39 @@
             return null;
         }
         catch (DataAccessException e) {
+            throw new KustvaktException(StatusCodes.CONNECTION_ERROR);
+        }
+    }
+
+
+    @Override
+    public List<Document> findbyPartialId (String id, User user)
+            throws KustvaktException {
+        MapSqlParameterSource s = new MapSqlParameterSource();
+        s.addValue("id", id + "%");
+
+        String sql = "select id, persistent_id, disabled, created from doc_store where persistent_id like :id;";
+        try {
+            return this.jdbcTemplate.query(sql, s, new RowMapper<Document>() {
+                @Override
+                public Document mapRow (ResultSet rs, int rowNum)
+                        throws SQLException {
+                    Document doc = null;
+                    if (!rs.isClosed()) {
+                        doc = new Document(rs.getString("persistent_id"));
+                        doc.setId(rs.getInt("id"));
+                        doc.setCreated(rs.getLong("created"));
+                        doc.setDisabled(rs.getBoolean("disabled"));
+                    }
+
+                    return doc;
+                }
+            });
+        }
+        catch (EmptyResultDataAccessException em) {
+            return null;
+        }
+        catch (DataAccessException e) {
             e.printStackTrace();
             throw new KustvaktException(StatusCodes.CONNECTION_ERROR);
         }
@@ -136,13 +173,14 @@
     }
 
 
+    //todo: remove and introduce partial match search of persistent id!
+    @Deprecated
     public List<Document> findbyCorpus (String corpus, int offset, int index)
             throws KustvaktException {
         MapSqlParameterSource source = new MapSqlParameterSource();
         source.addValue("corpus", corpus + "%");
         source.addValue("offset", (offset * index));
         source.addValue("limit", offset);
-        //strftime('%s', created) as
         final String sql = "select id, persistent_id, disabled, created from doc_store where (persistent_id like :corpus) limit :offset, :limit";
         try {
             return this.jdbcTemplate.query(sql, source,
@@ -174,6 +212,7 @@
     }
 
 
+    @Deprecated
     public List<String> findbyCorpus (String corpus, boolean disabled)
             throws KustvaktException {
         MapSqlParameterSource s = new MapSqlParameterSource();
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 aeeb58a..41b1c72 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java
@@ -151,6 +151,13 @@
 
 
     @Override
+    public <T1 extends KustvaktResource> List<T1> findbyPartialId (String id,
+            User user) throws KustvaktException {
+        return null;
+    }
+
+
+    @Override
     public int storeResource (T resource, User user) throws KustvaktException {
         MapSqlParameterSource source = new MapSqlParameterSource();
         KeyHolder holder = new GeneratedKeyHolder();
diff --git a/src/main/java/de/ids_mannheim/korap/interfaces/EncryptionIface.java b/src/main/java/de/ids_mannheim/korap/interfaces/EncryptionIface.java
index 7007fb8..7bd092d 100644
--- a/src/main/java/de/ids_mannheim/korap/interfaces/EncryptionIface.java
+++ b/src/main/java/de/ids_mannheim/korap/interfaces/EncryptionIface.java
@@ -23,20 +23,21 @@
      * @throws java.security.NoSuchAlgorithmException
      * @throws java.io.UnsupportedEncodingException
      */
-    public String produceSecureHash (String input, String salt)
+    public String secureHash (String input, String salt)
             throws NoSuchAlgorithmException, UnsupportedEncodingException,
             KustvaktException;
 
 
-    public String produceSecureHash (String input)
-            throws NoSuchAlgorithmException, UnsupportedEncodingException,
-            KustvaktException;
+    public String secureHash (String input) throws NoSuchAlgorithmException,
+            UnsupportedEncodingException, KustvaktException;
 
 
-    public String hash (String text, String salt) throws Exception;
+    //@Deprecated
+    //public String hash (String text, String salt) throws Exception;
 
 
-    public String hash (String text) throws Exception;
+    //@Deprecated
+    //public String hash (String text) throws Exception;
 
 
     /**
diff --git a/src/main/java/de/ids_mannheim/korap/interfaces/db/ResourceOperationIface.java b/src/main/java/de/ids_mannheim/korap/interfaces/db/ResourceOperationIface.java
index f13e254..43124a0 100644
--- a/src/main/java/de/ids_mannheim/korap/interfaces/db/ResourceOperationIface.java
+++ b/src/main/java/de/ids_mannheim/korap/interfaces/db/ResourceOperationIface.java
@@ -8,6 +8,7 @@
 
 import java.util.Collection;
 import java.util.List;
+import java.util.Set;
 
 // todo: for transaction to work this should go into core module!?!
 // todo: user instance only required for auditing pointcut operations
@@ -22,6 +23,11 @@
             throws KustvaktException;
 
 
+    // todo: regex should be considered here to consider determination of partial id offset information
+    <T extends KustvaktResource> List<T> findbyPartialId (String id, User user)
+            throws KustvaktException;
+
+
     List<T> getResources (Collection<Object> ids, User user)
             throws KustvaktException;
 
diff --git a/src/main/java/de/ids_mannheim/korap/interfaces/defaults/DefaultEncryption.java b/src/main/java/de/ids_mannheim/korap/interfaces/defaults/DefaultEncryption.java
index 96d5c52..3d56eff 100644
--- a/src/main/java/de/ids_mannheim/korap/interfaces/defaults/DefaultEncryption.java
+++ b/src/main/java/de/ids_mannheim/korap/interfaces/defaults/DefaultEncryption.java
@@ -28,7 +28,7 @@
 
 
     @Override
-    public String produceSecureHash (String input, String salt)
+    public String secureHash (String input, String salt)
             throws NoSuchAlgorithmException, UnsupportedEncodingException,
             KustvaktException {
         return null;
@@ -36,21 +36,8 @@
 
 
     @Override
-    public String produceSecureHash (String input)
-            throws NoSuchAlgorithmException, UnsupportedEncodingException,
-            KustvaktException {
-        return null;
-    }
-
-
-    @Override
-    public String hash (String text, String salt) throws Exception {
-        return null;
-    }
-
-
-    @Override
-    public String hash (String value) {
+    public String secureHash (String input) throws NoSuchAlgorithmException,
+            UnsupportedEncodingException, KustvaktException {
         return null;
     }
 
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 f45437e..057583e 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
@@ -78,13 +78,13 @@
     }
 
 
-    public String produceSecureHash (String input) {
-        return produceSecureHash(input, "");
+    public String secureHash (String input) {
+        return secureHash(input, "");
     }
 
 
     @Override
-    public String produceSecureHash (String input, String salt) {
+    public String secureHash (String input, String salt) {
         String hashString = "";
         switch (config.getEncryption()) {
             case ESAPICYPHER:
@@ -124,6 +124,7 @@
     }
 
 
+
     public String hash (String text, String salt) throws Exception {
         byte[] bytes;
 
@@ -143,7 +144,6 @@
     }
 
 
-    @Override
     public String hash (String input) {
         String hashString = "";
         MessageDigest md;
@@ -244,7 +244,7 @@
         String pw = "";
         switch (config.getEncryption()) {
             case ESAPICYPHER:
-                pw = produceSecureHash(plain, salt);
+                pw = secureHash(plain, salt);
                 break;
             case BCRYPT:
                 try {
@@ -265,7 +265,7 @@
     public boolean checkHash (String plain, String hash) {
         switch (config.getEncryption()) {
             case ESAPICYPHER:
-                return produceSecureHash(plain).equals(hash);
+                return secureHash(plain).equals(hash);
             case BCRYPT:
                 try {
                     return BCrypt.checkpw(plain, hash);
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/DocMatchRewrite.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/DocMatchRewrite.java
index fc47c8b..649f58d 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/DocMatchRewrite.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/DocMatchRewrite.java
@@ -35,9 +35,10 @@
     }
 
 
+    //todo: benchmark: see if retrieval and and get docs for all ids at once is better --> outside this rewrite handler
     @Override
     public JsonNode rewriteResult (KoralNode node) throws KustvaktException {
-        Document doc = null;
+        Document doc;
         if (this.docDao == null)
             throw new RuntimeException("Document dao must be set!");
 
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 3ede387..468fa9e 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
@@ -139,7 +139,6 @@
     }
 
 
-
     public void clear () {
         this.node_processors.clear();
         this.query_processors.clear();
diff --git a/src/main/java/de/ids_mannheim/korap/resources/Document.java b/src/main/java/de/ids_mannheim/korap/resources/Document.java
index c603011..c30e7d1 100644
--- a/src/main/java/de/ids_mannheim/korap/resources/Document.java
+++ b/src/main/java/de/ids_mannheim/korap/resources/Document.java
@@ -1,5 +1,7 @@
 package de.ids_mannheim.korap.resources;
 
+import bsh.StringUtil;
+import de.ids_mannheim.korap.utils.StringUtils;
 import lombok.Getter;
 import lombok.Setter;
 
@@ -14,30 +16,31 @@
 
     private String corpus;
     private boolean disabled;
+    private String docSigle;
 
 
-    public Document (String persistentID) {
+    public Document (String textSigle) {
+        this.setPersistentID(textSigle);
+        this.docSigle = StringUtils.getDocSigle(textSigle);
+        this.corpus = StringUtils.getCorpusSigle(textSigle);
+    }
+
+
+    public Document (String docSigle, String textSigle) {
         this.setId(-1);
-        this.setPersistentID(persistentID);
-        this.corpus = getCorpusID();
+        this.setPersistentID(textSigle);
+        this.docSigle = docSigle;
+        this.corpus = StringUtils.getCorpusSigle(textSigle);
         this.setDisabled(true);
     }
 
 
-    public Document (String persistentID, boolean disabled) {
-        this(persistentID);
+    public Document (String docsigle, String textSigle, boolean disabled) {
+        this(docsigle, textSigle);
         this.setDisabled(disabled);
     }
 
 
-    private String getCorpusID () {
-        //WPD_SSS.07367
-        if (this.getPersistentID() != null)
-            return this.getPersistentID().split("_")[0];
-        return null;
-    }
-
-
     public boolean isText () {
         return this.getPersistentID().contains(".");
     }
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 69ef5bf..977f797 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
@@ -11,6 +11,7 @@
 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;
@@ -46,7 +47,7 @@
         Element ein = invalided.get(authToken);
         if (e == null && ein == null) {
             try {
-                authToken = NamingUtils.stripTokenType(authToken);
+                authToken = StringUtils.stripTokenType(authToken);
                 context = signedToken.getTokenContext(authToken);
                 context.setTokenType(Attributes.API_AUTHENTICATION);
             }
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 ccad916..8c1ad22 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
@@ -12,6 +12,7 @@
 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;
 
@@ -25,17 +26,6 @@
 
     public static String[] decode (String token) {
         return OAuthUtils.decodeClientAuthenticationHeader(token);
-
-        //        String t = StringUtils.getTokenType(token);
-        //        if (t != null && t.toUpperCase()
-        //                .equals(Attributes.BASIC_AUTHENTICATION.toUpperCase())) {
-        //            token = StringUtils.stripTokenType(token);
-        //            String[] sp = new String(Base64.decodeBase64(token)).split(":", 2);
-        //            sp[0].replaceAll(" ", "");
-        //            sp[1].replaceAll(" ", "");
-        //            return sp;
-        //        }
-        //        return null;
     }
 
 
@@ -68,7 +58,7 @@
             c.setTokenType(Attributes.BASIC_AUTHENTICATION);
             // todo: for production mode, set true
             c.setSecureRequired(false);
-            c.setToken(NamingUtils.stripTokenType(authToken));
+            c.setToken(StringUtils.stripTokenType(authToken));
             //            fixme: you can make queries, but user sensitive data is off limits?!
             c.addContextParameter(Attributes.SCOPES,
                     Scopes.Scope.search.toString());
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 5c98f8f..f7387c4 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
@@ -14,6 +14,7 @@
 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;
@@ -79,7 +80,7 @@
         jlog.info("getting session status of token type '{}'",
                 token.split(" ")[0]);
         AuthenticationIface provider = getProvider(
-                NamingUtils.getTokenType(token), null);
+                StringUtils.getTokenType(token), null);
 
         if (provider == null)
             // throw exception for missing type paramter
@@ -398,7 +399,7 @@
                     StatusCodes.PASSWORD_RESET_FAILED);
 
         try {
-            user.setPassword(crypto.produceSecureHash(newPassword));
+            user.setPassword(crypto.secureHash(newPassword));
         }
         catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
             //            throw new KorAPException(StatusCodes.ILLEGAL_ARGUMENT,
@@ -431,7 +432,7 @@
         }
 
         try {
-            safePass = crypto.produceSecureHash(safePass);
+            safePass = crypto.secureHash(safePass);
         }
         catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
             jlog.error("Encoding/Algorithm Error", e);
@@ -514,7 +515,7 @@
                 (String) safeMap.get(Attributes.PASSWORD), Attributes.PASSWORD);
         String hash;
         try {
-            hash = crypto.produceSecureHash(safePass);
+            hash = crypto.secureHash(safePass);
         }
         catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
             jlog.error("Encryption error", e);
@@ -789,7 +790,7 @@
 
     private String cache_key (String input) throws KustvaktException {
         try {
-            return crypto.hash(KEY + "@" + input);
+            return crypto.secureHash(KEY + "@" + input);
         }
         catch (Exception e) {
             jlog.error("illegal cache key input '{}'", input);
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 e8de6c7..9515c93 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
@@ -12,6 +12,7 @@
 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;
@@ -41,7 +42,7 @@
     @Override
     public TokenContext getUserStatus (String authToken)
             throws KustvaktException {
-        authToken = NamingUtils.stripTokenType(authToken);
+        authToken = StringUtils.stripTokenType(authToken);
         return this.database.getContext(authToken);
     }
 
diff --git a/src/main/java/de/ids_mannheim/korap/utils/KoralCollectionQueryBuilder.java b/src/main/java/de/ids_mannheim/korap/utils/KoralCollectionQueryBuilder.java
index 86ac337..4744e07 100644
--- a/src/main/java/de/ids_mannheim/korap/utils/KoralCollectionQueryBuilder.java
+++ b/src/main/java/de/ids_mannheim/korap/utils/KoralCollectionQueryBuilder.java
@@ -92,7 +92,10 @@
     }
 
 
-    public Object rebaseCollection () {
+    public Object rebaseCollection (JsonNode node) {
+        if (node != null)
+            return mergeWith(node);
+
         if (this.builder.length() == 0 && this.base == null)
             return null;
 
@@ -125,18 +128,26 @@
 
     public JsonNode mergeWith (JsonNode node) {
         if (this.base != null) {
-            // check that collection non empty
             if (node != null) {
                 JsonNode tobase = node.at("/collection");
                 JsonNode base = this.base.deepCopy();
-                JsonNode result = JsonBuilder.buildDocGroup("and",
-                        base.at("/collection"), tobase);
+                JsonNode result = base.at("/collection");
+
+                if (result.isMissingNode() && !tobase.isMissingNode())
+                    result = tobase;
+                else if (result.isMissingNode() && tobase.isMissingNode())
+                    return base;
+                else {
+                    result = JsonBuilder.buildDocGroup(
+                            this.mergeOperator != null ? this.mergeOperator
+                                    .toLowerCase() : "and", result, tobase);
+                }
                 ((ObjectNode) base).put("collection", result);
                 return base;
             }
-            return null;
+            return this.base;
         }
-        return null;
+        throw new RuntimeException("no query found to merge with!");
     }
 
 
@@ -160,7 +171,12 @@
 
 
     public String toJSON () {
-        return JsonUtils.toJSON(rebaseCollection());
+        return JsonUtils.toJSON(rebaseCollection(null));
+    }
+
+
+    public String mergeToJSON (JsonNode node) {
+        return JsonUtils.toJSON(rebaseCollection(node));
     }
 
 
@@ -170,22 +186,6 @@
     }
 
 
-    @Deprecated
-    private KoralCollectionQueryBuilder 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;
-    }
-
     private static class JsonBuilder {
 
         public static ObjectNode buildDoc (String key, String value) {
diff --git a/src/main/java/de/ids_mannheim/korap/utils/NamingUtils.java b/src/main/java/de/ids_mannheim/korap/utils/NamingUtils.java
index 52f8663..beafb32 100644
--- a/src/main/java/de/ids_mannheim/korap/utils/NamingUtils.java
+++ b/src/main/java/de/ids_mannheim/korap/utils/NamingUtils.java
@@ -10,62 +10,10 @@
  */
 public class NamingUtils {
 
-    private static final String SLASH = "/";
 
 
     private NamingUtils () {}
 
 
-    public static Collection<String> joinStringSet (Collection<String> source,
-            String other) {
-        Set<String> set = new HashSet<>(source);
-        set.add(other);
-        return set;
-    }
-
-
-    public static Collection<UUID> joinUUIDSet (Collection<UUID> source,
-            UUID other) {
-        Set<UUID> set = new HashSet<>(source);
-        set.add(other);
-        return set;
-    }
-
-
-    public static String joinResources (String first, String second) {
-        String res;
-        if (first != null && !first.isEmpty())
-            res = first + SLASH + second;
-        else
-            res = second;
-        return res.replaceAll("\\s", "");
-    }
-
-
-    public static String[] splitAnnotations (String joined) {
-        String[] spl = joined.split(SLASH);
-        if (spl.length == 2)
-            return spl;
-        else
-            return null;
-    }
-
-
-    public static String stripTokenType (String token) {
-        int idx = token.lastIndexOf(" ");
-        if (idx == -1)
-            return token;
-        return token.substring(idx).replaceAll("\\s", "");
-    }
-
-
-    public static String getTokenType (String token) {
-        if (token.contains(" "))
-            return token.substring(0, token.lastIndexOf(" "))
-                    .replaceAll("\\s", "").toLowerCase();
-        else
-            return null;
-    }
-
 
 }
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 e5ab428..f942250 100644
--- a/src/main/java/de/ids_mannheim/korap/utils/StringUtils.java
+++ b/src/main/java/de/ids_mannheim/korap/utils/StringUtils.java
@@ -11,6 +11,7 @@
             .getLogger(StringUtils.class);
 
     private static final String SEP = ";";
+    private static final String SLASH = "/";
 
 
     public static Collection<UUID> stringToUUIDList (String s) {
@@ -136,4 +137,72 @@
         return StringEscapeUtils.unescapeHtml(value);
     }
 
+
+    public static String getDocSigle (String textSigle) {
+        if (textSigle != null)
+            return textSigle.split("\\.")[0];
+        return null;
+    }
+
+
+    public static String getCorpusSigle (String textSigle) {
+        //WPD_SSS.07367
+        if (textSigle != null)
+            return textSigle.split("_")[0];
+        return null;
+    }
+
+
+    public static Collection<String> joinStringSet (Collection<String> source,
+            String other) {
+        Set<String> set = new HashSet<>(source);
+        set.add(other);
+        return set;
+    }
+
+
+    public static Collection<UUID> joinUUIDSet (Collection<UUID> source,
+            UUID other) {
+        Set<UUID> set = new HashSet<>(source);
+        set.add(other);
+        return set;
+    }
+
+
+    public static String joinResources (String first, String second) {
+        String res;
+        if (first != null && !first.isEmpty())
+            res = first + SLASH + second;
+        else
+            res = second;
+        return res.replaceAll("\\s", "");
+    }
+
+
+    public static String[] splitAnnotations (String joined) {
+        String[] spl = joined.split(SLASH);
+        if (spl.length == 2)
+            return spl;
+        else
+            return null;
+    }
+
+
+    public static String stripTokenType (String token) {
+        int idx = token.lastIndexOf(" ");
+        if (idx == -1)
+            return token;
+        return token.substring(idx).replaceAll("\\s", "");
+    }
+
+
+    public static String getTokenType (String token) {
+        if (token.contains(" "))
+            return token.substring(0, token.lastIndexOf(" "))
+                    .replaceAll("\\s", "").toLowerCase();
+        else
+            return null;
+    }
+
+
 }
diff --git a/src/main/java/de/ids_mannheim/korap/utils/UserPropertyReader.java b/src/main/java/de/ids_mannheim/korap/utils/UserPropertyReader.java
index 4bc7055..70207fe 100644
--- a/src/main/java/de/ids_mannheim/korap/utils/UserPropertyReader.java
+++ b/src/main/java/de/ids_mannheim/korap/utils/UserPropertyReader.java
@@ -73,7 +73,7 @@
                 throw new KustvaktException(StatusCodes.ILLEGAL_ARGUMENT);
 
             try {
-                pass = crypto.produceSecureHash(pass);
+                pass = crypto.secureHash(pass);
             }
             catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
                 throw new KustvaktException(StatusCodes.REQUEST_INVALID);
@@ -93,7 +93,7 @@
                 throw new KustvaktException(StatusCodes.ILLEGAL_ARGUMENT);
 
             try {
-                pass = crypto.produceSecureHash(pass);
+                pass = crypto.secureHash(pass);
             }
             catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
                 throw new KustvaktException(StatusCodes.REQUEST_INVALID);
diff --git a/src/main/java/de/ids_mannheim/korap/web/filter/AdminFilter.java b/src/main/java/de/ids_mannheim/korap/web/filter/AdminFilter.java
index 29763fa..c06c3fe 100644
--- a/src/main/java/de/ids_mannheim/korap/web/filter/AdminFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/web/filter/AdminFilter.java
@@ -4,12 +4,14 @@
 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.AdminSetup;
 import de.ids_mannheim.korap.config.BeansFactory;
+import de.ids_mannheim.korap.interfaces.EncryptionIface;
 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 de.ids_mannheim.korap.web.utils.KorAPContext;
+import de.ids_mannheim.korap.web.utils.KustvaktContext;
 import de.ids_mannheim.korap.web.utils.KustvaktResponseHandler;
 
 import javax.ws.rs.ext.Provider;
@@ -21,7 +23,6 @@
 @Provider
 public class AdminFilter implements ContainerRequestFilter, ResourceFilter {
 
-    // check over ssl!
     @Override
     public ContainerRequest filter (ContainerRequest cr) {
         // todo:
@@ -31,18 +32,24 @@
         String authentication = cr
                 .getHeaderValue(ContainerRequest.AUTHORIZATION);
 
-        if (authentication != null
-                && authentication.endsWith(BeansFactory.getKustvaktContext()
-                        .getConfiguration().getAdminToken())) {
-            TokenContext c = new TokenContext();
-            c.setUsername(User.ADMINISTRATOR_NAME);
-            c.setTokenType(NamingUtils.getTokenType(authentication));
-            c.setToken(NamingUtils.stripTokenType(authentication));
-            cr.setSecurityContext(new KorAPContext(c));
+        //if (authentication != null
+        //        && authentication.endsWith(BeansFactory.getKustvaktContext()
+        //                .getConfiguration().getAdminToken())) {
+        if (authentication != null && cr.isSecure()) {
+            String token = StringUtils.stripTokenType(authentication);
+            EncryptionIface crypto = BeansFactory.getKustvaktContext()
+                    .getEncryption();
+
+            if (crypto.checkHash(token, AdminSetup.getInstance().getHash())) {
+                TokenContext c = new TokenContext();
+                c.setUsername(User.ADMINISTRATOR_NAME);
+                c.setTokenType(StringUtils.getTokenType(authentication));
+                c.setToken(StringUtils.stripTokenType(authentication));
+                cr.setSecurityContext(new KustvaktContext(c));
+            }
         }
         else
             throw KustvaktResponseHandler.throwAuthenticationException();
-
         return cr;
     }
 
diff --git a/src/main/java/de/ids_mannheim/korap/web/filter/AuthFilter.java b/src/main/java/de/ids_mannheim/korap/web/filter/AuthFilter.java
index df3157b..194d76d 100644
--- a/src/main/java/de/ids_mannheim/korap/web/filter/AuthFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/web/filter/AuthFilter.java
@@ -8,7 +8,7 @@
 import de.ids_mannheim.korap.exceptions.KustvaktException;
 import de.ids_mannheim.korap.interfaces.AuthenticationManagerIface;
 import de.ids_mannheim.korap.user.TokenContext;
-import de.ids_mannheim.korap.web.utils.KorAPContext;
+import de.ids_mannheim.korap.web.utils.KustvaktContext;
 import de.ids_mannheim.korap.web.utils.KustvaktResponseHandler;
 
 import javax.ws.rs.ext.Provider;
@@ -50,7 +50,7 @@
                     && context.isValid()
                     && ((context.isSecureRequired() && request.isSecure()) | !context
                             .isSecureRequired()))
-                request.setSecurityContext(new KorAPContext(context));
+                request.setSecurityContext(new KustvaktContext(context));
             else
                 throw KustvaktResponseHandler.throwAuthenticationException();
         }
diff --git a/src/main/java/de/ids_mannheim/korap/web/filter/DefaultFilter.java b/src/main/java/de/ids_mannheim/korap/web/filter/DefaultFilter.java
index 107c5e1..708a649 100644
--- a/src/main/java/de/ids_mannheim/korap/web/filter/DefaultFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/web/filter/DefaultFilter.java
@@ -8,7 +8,7 @@
 import de.ids_mannheim.korap.user.TokenContext;
 import de.ids_mannheim.korap.user.User;
 import de.ids_mannheim.korap.utils.TimeUtils;
-import de.ids_mannheim.korap.web.utils.KorAPContext;
+import de.ids_mannheim.korap.web.utils.KustvaktContext;
 
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.UriInfo;
@@ -42,8 +42,8 @@
                 // do nothing
             }
             if (pr == null)
-                request.setSecurityContext(new KorAPContext(createShorterToken(
-                        host, ua)));
+                request.setSecurityContext(new KustvaktContext(
+                        createShorterToken(host, ua)));
 
         }
         return request;
diff --git a/src/main/java/de/ids_mannheim/korap/web/filter/DemoFilter.java b/src/main/java/de/ids_mannheim/korap/web/filter/DemoFilter.java
index ff77428..2a06655 100644
--- a/src/main/java/de/ids_mannheim/korap/web/filter/DemoFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/web/filter/DemoFilter.java
@@ -7,7 +7,7 @@
 import de.ids_mannheim.korap.security.auth.BasicHttpAuth;
 import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.user.TokenContext;
-import de.ids_mannheim.korap.web.utils.KorAPContext;
+import de.ids_mannheim.korap.web.utils.KustvaktContext;
 
 import javax.ws.rs.core.SecurityContext;
 import javax.ws.rs.ext.Provider;
@@ -41,7 +41,7 @@
         context.setToken(token);
         context.setTokenType(Attributes.BASIC_AUTHENTICATION);
         context.setUsername("demo");
-        return new KorAPContext(context);
+        return new KustvaktContext(context);
     }
 
 
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 be4593f..ecb1133 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
@@ -29,11 +29,12 @@
                 .toUser(KustvaktConfiguration.KUSTVAKT_USER);
 
         KoralCollectionQueryBuilder bui = new KoralCollectionQueryBuilder();
-        bui.with("creationDate since 1775");
+        bui.with("creationDate since 1775 & corpusSigle=GOE");
 
         VirtualCollection c1 = new VirtualCollection();
         c1.setName("Weimarer Werke");
-        c1.addField(Attributes.QUERY, bui.toJSON());
+
+        c1.setFields(bui.toJSON());
 
         c1.setDescription("Goethe-Werke in Weimar (seit 1775)");
 
@@ -42,7 +43,7 @@
 
         VirtualCollection c2 = new VirtualCollection();
         c2.setName("Aphorismen");
-        c2.addField(Attributes.QUERY, bui.toJSON());
+        c2.setFields(bui.toJSON());
         c2.setDescription("Aphorismentexte Goethes");
 
         bui = new KoralCollectionQueryBuilder();
@@ -50,7 +51,7 @@
 
         VirtualCollection c3 = new VirtualCollection();
         c3.setName("Werther");
-        c3.addField(Attributes.QUERY, bui.toJSON());
+        c3.setFields(bui.toJSON());
         c3.setDescription("Goethe - Die Leiden des jungen Werther");
 
         PolicyBuilder b = new PolicyBuilder(user);
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/full/AdminService.java b/src/main/java/de/ids_mannheim/korap/web/service/full/AdminService.java
index 08fd322..21ac9b8 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/full/AdminService.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/full/AdminService.java
@@ -26,6 +26,7 @@
 import org.joda.time.format.DateTimeFormat;
 import org.joda.time.format.DateTimeFormatter;
 import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.ws.rs.*;
 import javax.ws.rs.core.Context;
@@ -42,7 +43,7 @@
 @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
 public class AdminService {
 
-    private static Logger jlog = KustvaktLogger.getLogger(AdminService.class);
+    private static Logger jlog = LoggerFactory.getLogger(AdminService.class);
     // todo: map in timeutils
     private static DateTimeFormatter dtf = DateTimeFormat
             .forPattern("dd/MM/yyyy");
@@ -136,9 +137,9 @@
     }
 
 
-    //fixme: documentservice?!
     @POST
     @Path("doc/{id}/add")
+    @Deprecated
     public Response addDocument (@PathParam("id") String id) {
         Document document = new Document(id);
         try {
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/full/DocumentService.java b/src/main/java/de/ids_mannheim/korap/web/service/full/DocumentService.java
index e1648d2..83dee9c 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/full/DocumentService.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/full/DocumentService.java
@@ -11,6 +11,7 @@
 import de.ids_mannheim.korap.web.filter.AdminFilter;
 import de.ids_mannheim.korap.web.utils.KustvaktResponseHandler;
 import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.ws.rs.*;
 import javax.ws.rs.core.MediaType;
@@ -26,8 +27,7 @@
 @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
 public class DocumentService {
 
-    private static Logger jlog = KustvaktLogger
-            .getLogger(DocumentService.class);
+    private static Logger jlog = LoggerFactory.getLogger(DocumentService.class);
     private DocumentDao documentDao;
 
 
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 9b04a14..0c54bd8 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
@@ -63,7 +63,6 @@
         this.config = BeansFactory.getKustvaktContext().getConfiguration();
         this.resourceHandler = new ResourceHandler();
         this.searchKrill = new SearchKrill(config.getIndexDir());
-
         UriBuilder builder = UriBuilder.fromUri("http://10.0.10.13").port(9997);
         this.graphDBhandler = new ClientsHandler(builder.build());
 
@@ -120,7 +119,7 @@
             @Context Locale locale, @PathParam("type") String type,
             @PathParam("id") String id, @PathParam("child") String child) {
         return getResource(context, locale, type,
-                NamingUtils.joinResources(id, child));
+                StringUtils.joinResources(id, child));
     }
 
 
@@ -275,6 +274,7 @@
     }
 
 
+    // ref query parameter removed!
     @TRACE
     @Path("search")
     public Response buildQuery (@Context Locale locale,
@@ -284,20 +284,21 @@
             @QueryParam("cutoff") Boolean cutoff,
             @QueryParam("count") Integer pageLength,
             @QueryParam("offset") Integer pageIndex,
-            @QueryParam("page") Integer startPage,
-            @QueryParam("ref") String reference, @QueryParam("cq") String cq) {
+            @QueryParam("page") Integer startPage, @QueryParam("cq") String cq) {
         TokenContext ctx = (TokenContext) securityContext.getUserPrincipal();
         QuerySerializer ss;
 
-        User user;
-        try {
-            user = controller.getUser(ctx.getUsername());
-        }
-        catch (KustvaktException e) {
-            throw KustvaktResponseHandler.throwit(e);
-        }
+        //User user;
+        //try {
+        //    user = controller.getUser(ctx.getUsername());
+        //}
+        //catch (KustvaktException e) {
+        //    throw KustvaktResponseHandler.throwit(e);
+        //}
 
         ss = new QuerySerializer().setQuery(q, ql, v);
+        if (cq != null)
+            ss.setCollection(cq);
 
         MetaQueryBuilder meta = new MetaQueryBuilder();
         if (pageIndex != null)
@@ -310,10 +311,10 @@
             meta.setSpanContext(context);
         meta.addEntry("cutOff", cutoff);
 
-        ss.setMeta(meta);
-
-        String query = this.processor.processQuery(ss.toJSON(), user);
-        return Response.ok(query).build();
+        ss.setMeta(meta.raw());
+        //fixme: parsing should be done only in search functions!
+        //String query = this.processor.processQuery(ss.toJSON(), user);
+        return Response.ok(ss.toJSON()).build();
     }
 
 
@@ -331,10 +332,10 @@
      * @return
      */
 
-    //todo: does cq have any sensible worth here?
+    //todo: does cq have any sensible worth here? --> would say no! --> is useful in non type/id scenarios
     @TRACE
     @Path("{type}/{id}/search")
-    public Response buildQuery (@Context Locale locale,
+    public Response buildQueryWithId (@Context Locale locale,
             @Context SecurityContext securityContext,
             @QueryParam("q") String q, @QueryParam("ql") String ql,
             @QueryParam("v") String v, @QueryParam("context") String context,
@@ -342,8 +343,7 @@
             @QueryParam("count") Integer pageLength,
             @QueryParam("offset") Integer pageIndex,
             @QueryParam("page") Integer startPage,
-            @PathParam("type") String type, @PathParam("id") String id,
-            @QueryParam("cq") String cq) {
+            @PathParam("type") String type, @PathParam("id") String id) {
         TokenContext ctx = (TokenContext) securityContext.getUserPrincipal();
         type = StringUtils.normalize(type);
         id = StringUtils.decodeHTML(id);
@@ -363,40 +363,38 @@
             meta.addEntry("cutOff", cutoff);
 
         ss.setMeta(meta.raw());
-        if (cq != null)
-            ss.setCollection(cq);
 
         KoralCollectionQueryBuilder cquery = new KoralCollectionQueryBuilder();
         cquery.setBaseQuery(ss.toJSON());
 
+        String query = "";
+        KustvaktResource resource;
         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));
-
-            // todo: test this
-            if (resource instanceof VirtualCollection)
-                cquery.mergeWith(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: instead of throwing exception, build notification and rewrites into result query
+            jlog.error("Exception encountered!");
+            throw KustvaktResponseHandler.throwit(e);
         }
 
-
-        // todo: policy parsing before return
-        return Response.ok(ss.toJSON()).build();
+        if (resource != null) {
+            if (resource instanceof VirtualCollection)
+                query = cquery.and().mergeToJSON(resource.getData());
+            else if (resource instanceof Corpus) {
+                cquery.and().with(
+                        Attributes.CORPUS_SIGLE + resource.getPersistentID());
+                query = cquery.toJSON();
+            }
+        }
+        return Response.ok(query).build();
     }
 
 
@@ -410,7 +408,7 @@
         // todo: should be possible to add the meta part to the query serialization
         try {
             User user = controller.getUser(ctx.getUsername());
-            jsonld = this.processor.processQuery(jsonld, user);
+            //jsonld = this.processor.processQuery(jsonld, user);
         }
         catch (KustvaktException e) {
             throw KustvaktResponseHandler.throwit(e);
@@ -418,6 +416,7 @@
         jlog.info("Serialized search: {}", jsonld);
 
         String result = searchKrill.search(jsonld);
+        // todo: logging
         KustvaktLogger.QUERY_LOGGER.trace("The result set: {}", result);
         return Response.ok(result).build();
     }
@@ -436,10 +435,8 @@
             @QueryParam("cq") String cq, @QueryParam("engine") String engine) {
         TokenContext context = (TokenContext) securityContext
                 .getUserPrincipal();
-        KoralCollectionQueryBuilder cquery = new KoralCollectionQueryBuilder();
         KustvaktConfiguration.BACKENDS eng = this.config.chooseBackend(engine);
         User user;
-        // todo: not added to query!!
         try {
             user = controller.getUser(context.getUsername());
         }
@@ -451,10 +448,8 @@
         QuerySerializer serializer = new QuerySerializer();
         serializer.setQuery(q, ql, v);
 
-        // todo: parse for security reasons
-        // todo: remove cq parameter
-        // if (cq != null)
-        //    serializer.setCollection(cq);
+        if (cq != null)
+            serializer.setCollection(cq);
 
         MetaQueryBuilder meta = new MetaQueryBuilder();
         meta.addEntry("startIndex", pageIndex);
@@ -468,8 +463,8 @@
         //        meta.addEntry("itemsPerResource", 1);
         serializer.setMeta(meta.raw());
 
-        //fixme: policy rewrite!
         String query = this.processor.processQuery(serializer.toJSON(), user);
+        //String query = serializer.toJSON();
 
         jlog.info("the serialized query {}", query);
 
@@ -489,7 +484,7 @@
             }
         }
         else
-            result = searchKrill.search(query);
+            result = searchKrill.search(serializer.toJSON());
         KustvaktLogger.QUERY_LOGGER.trace("The result set: {}", result);
         return Response.ok(result).build();
     }
@@ -567,7 +562,7 @@
                 meta.addEntry("cutoff", cutoff);
                 // should only apply to CQL queries
                 //                meta.addEntry("itemsPerResource", 1);
-                s.setMeta(meta);
+                s.setMeta(meta.raw());
 
                 query = s.toJSON();
                 //                PolicyParser parser = new PolicyParser(user);
@@ -633,11 +628,11 @@
 
     @GET
     @Path("{type}/{id}/{child}/stats")
-    public Response getStatisticsbyName (@Context SecurityContext context,
+    public Response getStatisticsbyIdChild (@Context SecurityContext context,
             @Context Locale locale, @PathParam("type") String type,
             @PathParam("id") String id, @PathParam("child") String child) {
         return getStatisticsbyId(context, locale, type,
-                NamingUtils.joinResources(id, child));
+                StringUtils.joinResources(id, child));
     }
 
 
@@ -928,7 +923,7 @@
             @Context Locale locale, @PathParam("type") String type,
             @PathParam("id") String id, @PathParam("child") String child) {
         return deleteResource(context, locale, type,
-                NamingUtils.joinResources(id, child));
+                StringUtils.joinResources(id, child));
     }
 
 
@@ -998,7 +993,7 @@
                     if (!manager.isAllowed())
                         continue;
 
-                    String[] sep = NamingUtils.splitAnnotations(spl);
+                    String[] sep = StringUtils.splitAnnotations(spl);
                     if (spl != null) {
                         f_list.add(sep[0]);
                         l_list.add(sep[1]);
@@ -1035,7 +1030,7 @@
             foundries = new HashSet<>();
             layers = new HashSet<>();
             for (Layer r : resources) {
-                String[] spl = NamingUtils.splitAnnotations(r.getName());
+                String[] spl = StringUtils.splitAnnotations(r.getName());
                 if (spl != null) {
                     foundries.add(spl[0]);
                     layers.add(spl[1]);
@@ -1061,7 +1056,7 @@
 
     // todo:?!
     @POST
-    @Path("match/{id}/save")
+    @Path("match/{id}")
     @Deprecated
     public Response save (@PathParam("{id}") String id,
             @QueryParam("d") String description,
@@ -1093,8 +1088,8 @@
     }
 
 
-    @POST
-    @Path("match/{id}/delete")
+    @DELETE
+    @Path("match/{id}")
     @Deprecated
     public Response remove (@PathParam("{id}") String id,
             @Context SecurityContext context) {
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 b55cb45..7c3b346 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
@@ -98,7 +98,7 @@
         meta.addEntry("count", pageLength);
         meta.setSpanContext(context);
         meta.addEntry("cutOff", cutoff);
-        ss.setMeta(meta);
+        ss.setMeta(meta.raw());
         if (cq != null)
             ss.setCollection(cq);
         return Response.ok(processor.processQuery(ss.toJSON(), null)).build();
@@ -138,7 +138,7 @@
                 pageInteger, pageLength, ctx, cutoff);
         if (fields != null && !fields.isEmpty())
             meta.addEntry("fields", fields);
-        serializer.setMeta(meta);
+        serializer.setMeta(meta.raw());
         if (cq != null)
             serializer.setCollection(cq);
 
@@ -212,7 +212,7 @@
             // should only apply to CQL queries
             //                meta.addEntry("itemsPerResource", 1);
             QuerySerializer s = new QuerySerializer().setQuery(query, ql, v)
-                    .setMeta(meta);
+                    .setMeta(meta.raw());
             query = processor.processQuery(s.toJSON(), null);
         }
         String result;
diff --git a/src/main/java/de/ids_mannheim/korap/web/utils/KorAPContext.java b/src/main/java/de/ids_mannheim/korap/web/utils/KustvaktContext.java
similarity index 86%
rename from src/main/java/de/ids_mannheim/korap/web/utils/KorAPContext.java
rename to src/main/java/de/ids_mannheim/korap/web/utils/KustvaktContext.java
index 2424d4b..f34cd43 100644
--- a/src/main/java/de/ids_mannheim/korap/web/utils/KorAPContext.java
+++ b/src/main/java/de/ids_mannheim/korap/web/utils/KustvaktContext.java
@@ -12,12 +12,12 @@
  *       wrapper for REST security context
  * 
  */
-public class KorAPContext implements SecurityContext {
+public class KustvaktContext implements SecurityContext {
 
     private TokenContext user;
 
 
-    public KorAPContext (final TokenContext user) {
+    public KustvaktContext (final TokenContext user) {
         this.user = user;
     }
 
diff --git a/src/main/resources/codes.kustvakt b/src/main/resources/codes.kustvakt
new file mode 100644
index 0000000..01fa0d8
--- /dev/null
+++ b/src/main/resources/codes.kustvakt
@@ -0,0 +1,2 @@
+[{code=100, message=}
+]
\ No newline at end of file
diff --git a/src/main/resources/db/sqlite/V1__Initial_version.sql b/src/main/resources/db/sqlite/V1__Initial_version.sql
index d109779..eaa32ff 100644
--- a/src/main/resources/db/sqlite/V1__Initial_version.sql
+++ b/src/main/resources/db/sqlite/V1__Initial_version.sql
@@ -86,6 +86,7 @@
 CREATE TABLE IF NOT EXISTS doc_store (
 id INTEGER PRIMARY KEY AUTOINCREMENT,
 persistent_id VARCHAR(100) UNIQUE,
+doc_sigle VARCHAR(100),
 created BIGINT NOT NULL DEFAULT CURRENT_TIMESTAMP,
 disabled BOOLEAN DEFAULT TRUE
 );