Index: src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java
===================================================================
--- src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java	(revision 59)
+++ src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java	(revision 63)
@@ -790,13 +790,11 @@
      * @param uri
      * @param userUri
-     * @param limit
-     * @param offset
-     * @return
-     */
-    public List<Annotation> searchAnnotationByUriUser(String targetUri, String userUri, String limit, String offset) {
+     * @return
+     */
+    public List<Annotation> searchAnnotationByUriUser(String targetUri, String userUri) {
         List<Annotation> annotations = new ArrayList<Annotation>();
         if (targetUri != null) {
             // there should be only one
-            Node target = getNodeIndex(NodeTypes.TARGET).get("uri", targetUri).getSingle();
+            Node target = getNodeFromIndex("uri", targetUri, NodeTypes.TARGET); 
             if (target != null) {
                 Iterable<Relationship> relations = target.getRelationships(RelationTypes.ANNOTATES);
@@ -829,4 +827,5 @@
         }
         // TODO: if both uri and user are given we should intersect
+        
         return annotations;
     }
Index: src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotations.java
===================================================================
--- src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotations.java	(revision 61)
+++ src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotations.java	(revision 63)
@@ -13,5 +13,4 @@
 import org.json.JSONObject;
 import org.restlet.data.Form;
-import org.restlet.data.Parameter;
 import org.restlet.data.Status;
 import org.restlet.ext.json.JsonRepresentation;
@@ -60,7 +59,13 @@
 
         if (id == null) {
-            return getAllAnnotations(authUser);
-        }
-
+            // no id -- send all annotations
+            Form form = getRequest().getResourceRef().getQueryAsForm();
+            int limit = getInt(form.getFirstValue("limit"));
+            int offset = getInt(form.getFirstValue("offset"));
+            String sortBy = form.getFirstValue("sortBy");
+            return getAllAnnotations(authUser, limit, offset, sortBy);
+        }
+
+        // send annotation with id
         AnnotationStore store = getAnnotationStore();
         Annotation annot = store.getAnnotationById(id);
@@ -71,6 +76,4 @@
             }
             JSONObject result = createAnnotatorJson(annot, (authUser == null));
-            logger.debug("sending:");
-            logger.debug(result);
             return new JsonRepresentation(result);
         } else {
@@ -81,33 +84,31 @@
     }
 
-    private Representation getAllAnnotations(Person authUser) {
-
-        Form form = getRequest().getResourceRef().getQueryAsForm();
-        String sortBy = null;
-        for (Parameter parameter : form) {
-            if (parameter.getName().equals("sortBy")) {
-                sortBy = parameter.getValue();
-            }
-        }
-
+    private Representation getAllAnnotations(Person authUser, int limit, int offset, String sortBy) {
         AnnotationStore store = getAnnotationStore();
         ArrayList<JSONObject> results = new ArrayList<JSONObject>();
-
+        
+        // read all annotations
         List<Annotation> annotations = store.getAnnotations(null, null);
         for (Annotation annotation : annotations) {
             // check permission
             if (!annotation.isActionAllowed("read", authUser, store)) continue;
-
+            // add annotation to list
             JSONObject jo = createAnnotatorJson(annotation, false);
             results.add(jo);
         }
 
+        // sort if necessary
         if (sortBy != null) {
             JSONObjectComparator.sortAnnotations(results, sortBy);
         }
-
-        JSONArray resultsJa = new JSONArray();
+        
+        // put in JSON list
+        JSONArray rows = new JSONArray();
+        int cnt = 0;
         for (JSONObject result : results) {
-            resultsJa.put(result);
+            cnt += 1;
+            if (offset > 0 && cnt < offset) continue;
+            rows.put(result);
+            if (limit > 0 && cnt >= limit) break;
         }
 
@@ -115,12 +116,10 @@
         JSONObject result = new JSONObject();
         try {
-            result.put("rows", resultsJa);
-            result.put("total", resultsJa.length());
+            result.put("rows", rows);
+            result.put("total", rows.length());
         } catch (JSONException e) {
             setStatus(Status.SERVER_ERROR_INTERNAL, "JSON Error");
             return null;
         }
-        logger.debug("sending:");
-        logger.debug(result);
         return new JsonRepresentation(result);
     }
@@ -234,8 +233,8 @@
             return retRep;
         } catch (JSONException e) {
-            e.printStackTrace();
+            logger.error("Error in doPutJSON", e);
             setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
         } catch (IOException e) {
-            e.printStackTrace();
+            logger.error("Error in doPutJSON", e);
             setStatus(Status.SERVER_ERROR_INTERNAL, "Other Error");
         }
@@ -269,5 +268,4 @@
             }
         }
-
         // delete annotation
         store.deleteAnnotationById(id);
Index: src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java
===================================================================
--- src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java	(revision 61)
+++ src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java	(revision 63)
@@ -387,9 +387,9 @@
             String y = geom.getString("y");
             fragment = String.format("xywh=fraction:%s,%s,0,0", x, y);
-        } else if (type.equalsIgnoreCase("point")) {
+        } else if (type.equalsIgnoreCase("rectangle")) {
             String x = geom.getString("x");
             String y = geom.getString("y");
-            String width = shape.getString("width");
-            String height = shape.getString("height");
+            String width = geom.getString("width");
+            String height = geom.getString("height");
             fragment = String.format("xywh=fraction:%s,%s,%s,%s", x, y, width, height);
         } else {
@@ -417,5 +417,4 @@
         String startOffset = range.getString("startOffset");
         String endOffset = range.getString("endOffset");
-
         String fragment = String.format(
                 "xpointer(start-point(string-range(\"%s\",%s,1))/range-to(end-point(string-range(\"%s\",%s,1))))", start,
@@ -560,8 +559,11 @@
         try {
             if (jo.has("ranges")) {
-                JSONObject ranges = jo.getJSONArray("ranges").getJSONObject(0);
-                annot.setFragmentType(FragmentTypes.XPOINTER);
-                String fragment = parseRange(ranges);
-                annot.setTargetFragment(fragment);
+                JSONArray ranges = jo.getJSONArray("ranges");
+                if (ranges.length() > 0) {
+                    JSONObject range = ranges.getJSONObject(0);
+                    annot.setFragmentType(FragmentTypes.XPOINTER);
+                    String fragment = parseRange(range);
+                    annot.setTargetFragment(fragment);
+                }
             }
         } catch (JSONException e) {
@@ -570,8 +572,11 @@
         try {
             if (jo.has("shapes")) {
-                JSONObject shapes = jo.getJSONArray("shapes").getJSONObject(0);
-                annot.setFragmentType(FragmentTypes.AREA);
-                String fragment = parseShape(shapes);
-                annot.setTargetFragment(fragment);
+                JSONArray shapes = jo.getJSONArray("shapes");
+                if (shapes.length() > 0) {
+                    JSONObject shape = shapes.getJSONObject(0);
+                    annot.setFragmentType(FragmentTypes.AREA);
+                    String fragment = parseShape(shape);
+                    annot.setTargetFragment(fragment);
+                }
             }
         } catch (JSONException e) {
@@ -581,13 +586,20 @@
         try {
             if (jo.has("areas")) {
-                JSONObject area = jo.getJSONArray("areas").getJSONObject(0);
-                annot.setFragmentType(FragmentTypes.AREA);
-                String fragment = parseArea(area);
-                annot.setTargetFragment(fragment);
+                JSONArray areas = jo.getJSONArray("areas");
+                if (areas.length() > 0) {
+                    JSONObject area = areas.getJSONObject(0);
+                    annot.setFragmentType(FragmentTypes.AREA);
+                    String fragment = parseArea(area);
+                    annot.setTargetFragment(fragment);
+                }
             }
         } catch (JSONException e) {
             // nothing to do
         }
-
+        // no fragment is an error
+        if (annot.getFragmentType() == null || annot.getTargetFragment() == null) {
+            throw new JSONException("Annotation has no valid target fragment!");
+        }
+        
         /*
          * permissions
@@ -650,5 +662,5 @@
     }
 
-    public float getFloat(String s) {
+    public static float getFloat(String s) {
         try {
             return Float.parseFloat(s);
@@ -657,3 +669,11 @@
         return 0f;
     }
+
+    public static int getInt(String s) {
+        try {
+            return Integer.parseInt(s);
+        } catch (NumberFormatException e) {
+        }
+        return 0;
+    }
 }
Index: src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorRestlet.java
===================================================================
--- src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorRestlet.java	(revision 62)
+++ src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorRestlet.java	(revision 63)
@@ -15,5 +15,5 @@
 public class AnnotatorRestlet extends BaseRestlet {
 
-    public final String version = "AnnotationManagerN4J/Annotator 0.3.0";
+    public final String version = "AnnotationManagerN4J/Annotator 0.3.1";
 
     public static Logger logger = Logger.getLogger(AnnotatorRestlet.class);
Index: src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorSearch.java
===================================================================
--- src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorSearch.java	(revision 32)
+++ src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorSearch.java	(revision 63)
@@ -4,4 +4,5 @@
 package de.mpiwg.itgroup.annotations.restlet;
 
+import java.util.ArrayList;
 import java.util.List;
 
@@ -18,4 +19,5 @@
 import de.mpiwg.itgroup.annotations.Person;
 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
+import de.mpiwg.itgroup.annotations.restlet.utils.JSONObjectComparator;
 
 /**
@@ -34,5 +36,5 @@
     /**
      * result for JSON content-type. optional search parameters: uri, user, limit,
-     * offset.
+     * offset, sortBy.
      * 
      * @param entity
@@ -50,12 +52,13 @@
         String uri = form.getFirstValue("uri");
         String user = form.getFirstValue("user");
-        String limit = form.getFirstValue("limit");
-        String offset = form.getFirstValue("offset");
+        int limit = getInt(form.getFirstValue("limit"));
+        int offset = getInt(form.getFirstValue("offset"));
+        String sortBy = form.getFirstValue("sortBy");
 
-        JSONArray results = new JSONArray();
         // do search
+        ArrayList<JSONObject> results = new ArrayList<JSONObject>();
         logger.debug(String.format("searching for uri=%s user=%s", uri, user));
         AnnotationStore store = getAnnotationStore();
-        List<Annotation> annots = store.searchAnnotationByUriUser(uri, user, limit, offset);
+        List<Annotation> annots = store.searchAnnotationByUriUser(uri, user);
         for (Annotation annot : annots) {
             // check permission
@@ -63,5 +66,5 @@
             JSONObject jo = createAnnotatorJson(annot, (authUser == null));
             if (jo != null) {
-                results.put(jo);
+                results.add(jo);
             } else {
                 setStatus(Status.SERVER_ERROR_INTERNAL, "JSON Error");
@@ -69,9 +72,25 @@
             }
         }
+
+        // sort if necessary
+        if (sortBy != null) {
+            JSONObjectComparator.sortAnnotations(results, sortBy);
+        }
+        
+        // put in JSON list
+        JSONArray rows = new JSONArray();
+        int cnt = 0;
+        for (JSONObject result : results) {
+            cnt += 1;
+            if (offset > 0 && cnt < offset) continue;
+            rows.put(result);
+            if (limit > 0 && cnt >= limit) break;
+        }
+
         // assemble result object
         JSONObject result = new JSONObject();
         try {
-            result.put("rows", results);
-            result.put("total", results.length());
+            result.put("rows", rows);
+            result.put("total", rows.length());
         } catch (JSONException e) {
             setStatus(Status.SERVER_ERROR_INTERNAL, "JSON Error");
Index: src/main/java/de/mpiwg/itgroup/annotations/restlet/utils/JSONObjectComparator.java
===================================================================
--- src/main/java/de/mpiwg/itgroup/annotations/restlet/utils/JSONObjectComparator.java	(revision 31)
+++ src/main/java/de/mpiwg/itgroup/annotations/restlet/utils/JSONObjectComparator.java	(revision 63)
@@ -3,6 +3,4 @@
 import java.util.Comparator;
 import java.util.List;
-
-import de.mpiwg.itgroup.annotations.Annotation;
 
 import org.json.JSONException;
