 +////////////////////////////////////////////////////////////////////////////////
 +/// @}
 +////////////////////////////////////////////////////////////////////////////////
-+
-+// -----------------------------------------------------------------------------
+ 
+ // -----------------------------------------------------------------------------
  // --SECTION--                                                  HELPER FUNCTIONS
- // -----------------------------------------------------------------------------
- 
-@@ -513,7 +579,9 @@ static v8::Handle<v8::Value> DocumentVocbaseCol (TRI_vocbase_t* vocbase,
+@@ -476,14 +535,19 @@ static v8::Handle<v8::Value> EnsurePathIndex (string const& cmd,
+ 
+ ////////////////////////////////////////////////////////////////////////////////
+ /// @brief looks up a document
++///
++/// it is the caller's responsibility to acquire and release the required locks
++/// the collection must also have the correct status already. don't use this
++/// function if you're unsure about it!
+ ////////////////////////////////////////////////////////////////////////////////
+ 
+ static v8::Handle<v8::Value> DocumentVocbaseCol (TRI_vocbase_t* vocbase,
+                                                  TRI_vocbase_col_t const* collection,
+-                                                 v8::Arguments const& argv) {
++                                                 v8::Arguments const& argv,
++                                                 const bool lock) {
+   v8::HandleScope scope;
+ 
+-  // first and only argument schould be a document idenfifier
++  // first and only argument should be a document idenfifier
+   if (argv.Length() != 1) {
+     return scope.Close(v8::ThrowException(
+                          TRI_CreateErrorObject(TRI_ERROR_BAD_PARAMETER,
+@@ -492,10 +556,10 @@ static v8::Handle<v8::Value> DocumentVocbaseCol (TRI_vocbase_t* vocbase,
+ 
+   TRI_voc_did_t did;
+   TRI_voc_rid_t rid;
+-  v8::Handle<v8::Value> err = TRI_ParseDocumentOrDocumentHandle(vocbase, collection, did, rid, argv[0]);
++  v8::Handle<v8::Value> err = TRI_ParseDocumentOrDocumentHandle(vocbase, collection, did, rid, lock, argv[0]);
+ 
+   if (! err.IsEmpty()) {
+-    if (collection != 0) {
++    if (collection != 0 && lock) {
+       TRI_ReleaseCollection(collection);
+     }
+ 
+@@ -513,7 +577,9 @@ static v8::Handle<v8::Value> DocumentVocbaseCol (TRI_vocbase_t* vocbase,
    // inside a read transaction
    // .............................................................................
  
-+  LOG_TRACE("before beginRead");
-   collection->_collection->beginRead(collection->_collection);
-+  LOG_TRACE("after beginRead");
+-  collection->_collection->beginRead(collection->_collection);
++  if (lock) {
++    collection->_collection->beginRead(collection->_collection);
++  }
  
    document = collection->_collection->read(collection->_collection, did);
  
-@@ -524,7 +592,9 @@ static v8::Handle<v8::Value> DocumentVocbaseCol (TRI_vocbase_t* vocbase,
+@@ -524,13 +590,17 @@ static v8::Handle<v8::Value> DocumentVocbaseCol (TRI_vocbase_t* vocbase,
      result = TRI_WrapShapedJson(collection, &document, barrier);
    }
  
-+  LOG_TRACE("before endRead");
-   collection->_collection->endRead(collection->_collection);
-+  LOG_TRACE("after beginRead");
+-  collection->_collection->endRead(collection->_collection);
++  if (lock) {
++    collection->_collection->endRead(collection->_collection);
++  }
  
    // .............................................................................
    // outside a write transaction
-@@ -610,7 +680,9 @@ static v8::Handle<v8::Value> ReplaceVocbaseCol (TRI_vocbase_t* vocbase,
-   // inside a write transaction
    // .............................................................................
  
-+  LOG_TRACE("before beginWrite");
-   collection->_collection->beginWrite(collection->_collection);
-+  LOG_TRACE("after beginWrite");
- 
-   TRI_voc_rid_t oldRid = 0;
-   TRI_doc_mptr_t mptr = doc->update(doc, shaped, did, rid, &oldRid, policy, true);
-@@ -1006,6 +1078,7 @@ static v8::Handle<v8::Value> ExecuteQueryNativeAhuacatl (TRI_aql_context_t* cons
-                                                          const TRI_json_t* const parameters) {
-   v8::HandleScope scope;
- 
-+  LOGGER_DEBUG << "executing native query";
-   // parse & validate
-   // bind values
-   // optimise
-@@ -1014,21 +1087,28 @@ static v8::Handle<v8::Value> ExecuteQueryNativeAhuacatl (TRI_aql_context_t* cons
-       !TRI_BindQueryContextAql(context, parameters) ||
-       !TRI_LockQueryContextAql(context) ||
-       !TRI_OptimiseQueryContextAql(context)) {
-+    LOGGER_DEBUG << "executing native query failed";
-     v8::Handle<v8::Object> errorObject = CreateErrorObjectAhuacatl(&context->_error);
- 
-     return scope.Close(v8::ThrowException(errorObject));
-   }
- 
-+  LOGGER_DEBUG << "generating code for native query";
-   // generate code
-   char* code = TRI_GenerateCodeAql(context);
-+  LOGGER_DEBUG << "generating code finished";
-   if (!code) {
-+    LOGGER_DEBUG << "generating code failed";
-     v8::Handle<v8::Object> errorObject = CreateErrorObjectAhuacatl(&context->_error);
- 
-     return scope.Close(v8::ThrowException(errorObject));
-   }
-+  LOGGER_DEBUG << "generating code succeeded";
- 
-   // execute code
-+  LOGGER_DEBUG << "executing generated Javascript code";
-   v8::Handle<v8::Value> result = TRI_ExecuteJavaScriptString(v8::Context::GetCurrent(), v8::String::New(code), v8::String::New("query"), false);
-+  LOGGER_DEBUG << "finished executing generated Javascript code";
-   TRI_Free(TRI_UNKNOWN_MEM_ZONE, code);
- 
-   // return the result as a javascript array
-@@ -1048,14 +1128,18 @@ static v8::Handle<v8::Value> ExecuteQueryCursorAhuacatl (TRI_vocbase_t* const vo
-   v8::HandleScope scope;
-   v8::TryCatch tryCatch;
- 
-+  LOGGER_DEBUG << "executing query cursor";
-   v8::Handle<v8::Value> result = ExecuteQueryNativeAhuacatl(context, parameters);
-+  LOGGER_DEBUG << "finished executing query cursor";
- 
-   if (tryCatch.HasCaught()) {
-+    LOGGER_DEBUG << "executing query cursor failed";
-     return scope.Close(v8::ThrowException(tryCatch.Exception()));
-   }
- 
-   if (allowDirectReturn || !result->IsArray()) {
-     // return the value we got as it is. this is a performance optimisation
-+    LOGGER_DEBUG << "executing query cursor returned directly";
-     return scope.Close(result);
-   }
- 
-@@ -1063,6 +1147,7 @@ static v8::Handle<v8::Value> ExecuteQueryCursorAhuacatl (TRI_vocbase_t* const vo
-   TRI_json_t* json = TRI_JsonObject(result);
- 
-   if (!json) {
-+    LOGGER_DEBUG << "executing query cursor failed with out-of-memory";
-     v8::Handle<v8::Object> errorObject = TRI_CreateErrorObject(TRI_ERROR_OUT_OF_MEMORY, "out of memory");
- 
-     return scope.Close(v8::ThrowException(errorObject));
-@@ -1073,6 +1158,7 @@ static v8::Handle<v8::Value> ExecuteQueryCursorAhuacatl (TRI_vocbase_t* const vo
-   if (!cursorResult) {
-     TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
- 
-+    LOGGER_DEBUG << "executing query cursor failed with out-of-memory at cursor result";
-     v8::Handle<v8::Object> errorObject = TRI_CreateErrorObject(TRI_ERROR_OUT_OF_MEMORY, "out of memory");
- 
-     return scope.Close(v8::ThrowException(errorObject));
-@@ -1083,6 +1169,7 @@ static v8::Handle<v8::Value> ExecuteQueryCursorAhuacatl (TRI_vocbase_t* const vo
-     TRI_Free(TRI_UNKNOWN_MEM_ZONE, cursorResult);
-     TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
- 
-+    LOGGER_DEBUG << "creating general cursor failed";
-     v8::Handle<v8::Object> errorObject = TRI_CreateErrorObject(TRI_ERROR_OUT_OF_MEMORY, "out of memory");
- 
-     return scope.Close(v8::ThrowException(errorObject));
-@@ -1091,6 +1178,7 @@ static v8::Handle<v8::Value> ExecuteQueryCursorAhuacatl (TRI_vocbase_t* const vo
-   assert(cursor);
-   TRI_StoreShadowData(vocbase->_cursors, (const void* const) cursor);
- 
-+  LOGGER_DEBUG << "returning general cursor";
-   return scope.Close(WrapGeneralCursor(cursor));
- }
- 
-@@ -1299,12 +1387,10 @@ static v8::Handle<v8::Value> JS_DisposeGeneralCursor (v8::Arguments const& argv)
-   bool found = TRI_DeleteDataShadowData(vocbase->_cursors, UnwrapGeneralCursor(argv.Holder()));
- 
-   if (found) {
--    return scope.Close(v8::True());
--  }
--
+-  TRI_ReleaseCollection(collection);
++  if (lock) {
++    TRI_ReleaseCollection(collection);
++  }
+ 
+   if (document._did == 0) {
+     return scope.Close(v8::ThrowException(
+@@ -571,7 +641,7 @@ static v8::Handle<v8::Value> ReplaceVocbaseCol (TRI_vocbase_t* vocbase,
+   TRI_voc_did_t did;
+   TRI_voc_rid_t rid;
+ 
+-  v8::Handle<v8::Value> err = TRI_ParseDocumentOrDocumentHandle(vocbase, collection, did, rid, argv[0]);
++  v8::Handle<v8::Value> err = TRI_ParseDocumentOrDocumentHandle(vocbase, collection, did, rid, true, argv[0]);
+ 
+   if (! err.IsEmpty()) {
+     if (collection != 0) {
+@@ -658,7 +728,7 @@ static v8::Handle<v8::Value> DeleteVocbaseCol (TRI_vocbase_t* vocbase,
+   TRI_voc_did_t did;
+   TRI_voc_rid_t rid;
+ 
+-  v8::Handle<v8::Value> err = TRI_ParseDocumentOrDocumentHandle(vocbase, collection, did, rid, argv[0]);
++  v8::Handle<v8::Value> err = TRI_ParseDocumentOrDocumentHandle(vocbase, collection, did, rid, true, argv[0]);
+ 
+   if (! err.IsEmpty()) {
+     if (collection != 0) {
+@@ -1302,9 +1372,7 @@ static v8::Handle<v8::Value> JS_DisposeGeneralCursor (v8::Arguments const& argv)
+     return scope.Close(v8::True());
+   }
+ 
 -  return scope.Close(v8::ThrowException(
 -                       TRI_CreateErrorObject(TRI_ERROR_CURSOR_NOT_FOUND,
 -                                             "disposed or unknown cursor")));
-+     return scope.Close(v8::True());
-+   }
++  return scope.Close(v8::False());
+ }
+ 
+ ////////////////////////////////////////////////////////////////////////////////
+@@ -1664,6 +1732,32 @@ static v8::Handle<v8::Value> JS_HasNextGeneralCursor (v8::Arguments const& argv)
+                        TRI_CreateErrorObject(TRI_ERROR_CURSOR_NOT_FOUND,
+                                              "disposed or unknown cursor")));
+ }
 + 
-+  return scope.Close(v8::False()); 
- }
- 
- ////////////////////////////////////////////////////////////////////////////////
-@@ -1365,7 +1451,7 @@ static v8::Handle<v8::Value> JS_CountGeneralCursor (v8::Arguments const& argv) {
-   cursor = (TRI_general_cursor_t*) TRI_BeginUsageDataShadowData(vocbase->_cursors, UnwrapGeneralCursor(argv.Holder()));
- 
-   if (cursor) {
--    size_t  length = (size_t) cursor->_length;
-+    size_t length = (size_t) cursor->_length;
-     TRI_EndUsageDataShadowData(vocbase->_cursors, cursor);
-     return scope.Close(v8::Number::New(length));
-   }
-@@ -1666,6 +1752,32 @@ static v8::Handle<v8::Value> JS_HasNextGeneralCursor (v8::Arguments const& argv)
- }
- 
- ////////////////////////////////////////////////////////////////////////////////
++////////////////////////////////////////////////////////////////////////////////
 +/// @brief unuse a general cursor
 +////////////////////////////////////////////////////////////////////////////////
 +

diff --git a/arangod/Ahuacatl/ahuacatl-codegen.c b/arangod/Ahuacatl/ahuacatl-codegen.c
index 737ea0f..f390315 100644
--- a/arangod/Ahuacatl/ahuacatl-codegen.c
+++ b/arangod/Ahuacatl/ahuacatl-codegen.c
@@ -2253,9 +2253,12 @@ char* TRI_GenerateCodeAql (TRI_aql_context_t* const context) {
   char* code;
 
   assert(context);
+    
+  TRI_AQL_LOG("generating code");
 
   generator = CreateGenerator(context);
   if (generator == NULL) {
+    TRI_AQL_LOG("could not create code generator");
     return NULL;
   }
 
@@ -2272,6 +2275,7 @@ char* TRI_GenerateCodeAql (TRI_aql_context_t* const context) {
   OutputString(&generator->_buffer, "})()");
 
   if (generator->_error) {
+    TRI_AQL_LOG("generating code failed");
     FreeGenerator(generator);
 
     return NULL;
@@ -2283,9 +2287,11 @@ char* TRI_GenerateCodeAql (TRI_aql_context_t* const context) {
   FreeGenerator(generator);
 
   if (code) {
-    TRI_AQL_DUMP("generated code: %s\n", code);
+    TRI_AQL_LOG("generated code: %s\n", code);
   }
 
+  TRI_AQL_LOG("generating code successful");
+
   return code;
 }
 
diff --git a/arangod/Ahuacatl/ahuacatl-collections.c b/arangod/Ahuacatl/ahuacatl-collections.c
index 3113434..4d63eb8 100644
--- a/arangod/Ahuacatl/ahuacatl-collections.c
+++ b/arangod/Ahuacatl/ahuacatl-collections.c
@@ -399,15 +399,19 @@ bool TRI_ReadLockCollectionsAql (TRI_aql_context_t* const context) {
 
     TRI_AQL_LOG("read-locking collection '%s'", collection->_name);
 
+    LOG_TRACE("before beginRead");
     lockResult = documentCollection->beginRead(documentCollection);
+    LOG_TRACE("after beginRead");
     if (lockResult != TRI_ERROR_NO_ERROR) {
       // couldn't acquire the read lock
+      LOG_WARNING("read-locking collection '%s' failed", collection->_name);
       result = false;
       TRI_SetErrorContextAql(context, TRI_ERROR_QUERY_COLLECTION_LOCK_FAILED, collection->_name);
       break;
     }
     else {
       collection->_readLocked = true;
+      TRI_AQL_LOG("read-locked collection '%s'", collection->_name);
     }
   }
 
@@ -447,7 +451,9 @@ void TRI_ReadUnlockCollectionsAql (TRI_aql_context_t* const context) {
 
     TRI_AQL_LOG("read-unlocking collection '%s'", collection->_name);
 
+    LOG_TRACE("before endRead");
     documentCollection->endRead(documentCollection);
+    LOG_TRACE("after endRead");
     collection->_readLocked = false;
   }
 }
@@ -484,6 +490,7 @@ bool TRI_AddBarrierCollectionsAql (TRI_aql_context_t* const context) {
     if (!ce) {
       // couldn't create the barrier
       result = false;
+      LOG_WARNING("adding barrier for collection '%s' failed", collection->_name);
       TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
       break;
     }
diff --git a/arangod/Ahuacatl/ahuacatl-context.c b/arangod/Ahuacatl/ahuacatl-context.c
index b4a426c..b5e107a 100644
--- a/arangod/Ahuacatl/ahuacatl-context.c
+++ b/arangod/Ahuacatl/ahuacatl-context.c
@@ -279,21 +279,30 @@ void TRI_FreeContextAql (TRI_aql_context_t* const context) {
 ////////////////////////////////////////////////////////////////////////////////
   
 bool TRI_ValidateQueryContextAql (TRI_aql_context_t* const context) {
+  TRI_AQL_LOG("validating query context");
+
   if (context->_parser->_length == 0) {
     // query is empty, no need to parse it
+    TRI_AQL_LOG("validating query context failed");
     TRI_SetErrorContextAql(context, TRI_ERROR_QUERY_EMPTY, NULL);
     return false;
   }
+    
+  TRI_AQL_LOG("validating query context parse");
 
   // parse the query
   if (!TRI_ParseAql(context)) {
     // lexing/parsing failed
+    TRI_AQL_LOG("validating query context parse failed");
     return false;
   }
 
   if (context->_error._code) {
+    TRI_AQL_LOG("validating query context failed with error %d", (int) context->_error._code);
     return false;
   }
+  
+  TRI_AQL_LOG("validating query context successful");
 
   return true;
 }
@@ -335,19 +344,26 @@ bool TRI_BindQueryContextAql (TRI_aql_context_t* const context,
 ////////////////////////////////////////////////////////////////////////////////
 
 bool TRI_OptimiseQueryContextAql (TRI_aql_context_t* const context) {
+  TRI_AQL_LOG("performing query optimisations");
+
   // do some basic optimisations in the AST
   if (!TRI_OptimiseAql(context)) {
-    // constant folding failed
+    // optimisations failed
+    TRI_AQL_LOG("performing query optimisations failed");
+
     return false;
   }
 
   if (context->_error._code) {
+    TRI_AQL_LOG("performing query optimisations failed with error code %d", (int) context->_error._code);
     return false;
   }
 
+  TRI_AQL_LOG("performing query optimisations compacting");
   TRI_CompactStatementListAql(context->_statements);
+  TRI_AQL_LOG("performing query optimisations compacting successful");
 
-  // TRI_DumpStatementsAql(context->_statements);
+  TRI_AQL_LOG("performing query optimisations successful");
 
   return true;
 }
@@ -357,24 +373,35 @@ bool TRI_OptimiseQueryContextAql (TRI_aql_context_t* const context) {
 ////////////////////////////////////////////////////////////////////////////////
 
 bool TRI_LockQueryContextAql (TRI_aql_context_t* const context) {
+  TRI_AQL_LOG("performing query locking");
+
   // mark all used collections as being used
   if (!TRI_LockCollectionsAql(context)) {
     return false;
   }
 
+  TRI_AQL_LOG("performing query locking read");
+
   // acquire read locks on all collections used
   if (!TRI_ReadLockCollectionsAql(context)) {
+    TRI_AQL_LOG("performing query locking read failed");
     return false;
   }
   
+  TRI_AQL_LOG("performing query locking barrier");
+
   // add barriers for all collections used
   if (!TRI_AddBarrierCollectionsAql(context)) {
+    TRI_AQL_LOG("performing query locking barrier failed");
     return false;
   }
   
   if (context->_error._code) {
+    TRI_AQL_LOG("performing query locking failed with error code %d", (int) context->_error._code);
     return false;
   }
+ 
+  TRI_AQL_LOG("performing query locking successful");
 
   return true;
 }
diff --git a/arangod/Ahuacatl/ahuacatl-log.h b/arangod/Ahuacatl/ahuacatl-log.h
index f8e92b7..aa5cf5e 100644
--- a/arangod/Ahuacatl/ahuacatl-log.h
+++ b/arangod/Ahuacatl/ahuacatl-log.h
@@ -35,7 +35,7 @@ extern "C" {
 #endif
 
 #undef TRI_DEBUG_AQL  
-//#define TRI_DEBUG_AQL 1
+#define TRI_DEBUG_AQL 1
 
 // -----------------------------------------------------------------------------
 // --SECTION--                                                     public macros
@@ -52,10 +52,8 @@ extern "C" {
 
 #ifdef TRI_DEBUG_AQL
 #define TRI_AQL_LOG(...) LOG_INFO(__VA_ARGS__);
-#define TRI_AQL_DUMP(format, ...) printf(format, __VA_ARGS__);
 #else
 #define TRI_AQL_LOG(...) LOG_TRACE(__VA_ARGS__);
-#define TRI_AQL_DUMP(...) { };
 #endif
 
 ////////////////////////////////////////////////////////////////////////////////
diff --git a/arangod/Ahuacatl/ahuacatl-optimiser.c b/arangod/Ahuacatl/ahuacatl-optimiser.c
index 49437aa..43d905b 100644
--- a/arangod/Ahuacatl/ahuacatl-optimiser.c
+++ b/arangod/Ahuacatl/ahuacatl-optimiser.c
@@ -1076,14 +1076,22 @@ static bool DetermineIndexes (TRI_aql_context_t* const context) {
 ////////////////////////////////////////////////////////////////////////////////
 
 bool TRI_OptimiseAql (TRI_aql_context_t* const context) {
+  LOG_TRACE("optimising");
+
+  LOG_TRACE("optimising AST");
   if (!OptimiseAst(context)) {
+    LOG_TRACE("optimising AST failed");
     return false;
   }
 
+  LOG_TRACE("determining indexes");
   if (!DetermineIndexes(context)) {
+    LOG_TRACE("determining indexes failed");
     return false;
   }
 
+  LOG_TRACE("optimising successful");
+
   return true;
 }
 
diff --git a/arangod/RestHandler/RestDocumentHandler.cpp b/arangod/RestHandler/RestDocumentHandler.cpp
index e8fb467..026654d 100644
--- a/arangod/RestHandler/RestDocumentHandler.cpp
+++ b/arangod/RestHandler/RestDocumentHandler.cpp
@@ -270,13 +270,18 @@ bool RestDocumentHandler::createDocument () {
   // inside write transaction
   // .............................................................................
 
-  _documentCollection->beginWrite(_documentCollection);
+  LOG_TRACE("before beginWrite");
+  int lockResult = _documentCollection->beginWrite(_documentCollection);
+  LOG_TRACE("after beginWrite");
+  LOGGER_TRACE << "result of beginWrite: " << lockResult;
 
   bool waitForSync = _documentCollection->base._waitForSync;
   TRI_voc_cid_t cid = _documentCollection->base._cid;
 
   // note: unlocked is performed by createJson()
+  LOGGER_TRACE << "creating document";
   TRI_doc_mptr_t const mptr = _documentCollection->createJson(_documentCollection, TRI_DOC_MARKER_DOCUMENT, json, 0, reuseId, true);
+  LOGGER_TRACE << "finished creating document";
 
   // .............................................................................
   // outside write transaction
@@ -284,6 +289,7 @@ bool RestDocumentHandler::createDocument () {
 
   // release collection and free json
   releaseCollection();
+  LOGGER_TRACE << "released collection again";
 
   // generate result
   if (mptr._did != 0) {
@@ -415,12 +421,17 @@ bool RestDocumentHandler::readSingleDocument (bool generateBody) {
   // inside read transaction
   // .............................................................................
 
-  _documentCollection->beginRead(_documentCollection);
+  LOG_TRACE("before beginRead");
+  int lockResult = _documentCollection->beginRead(_documentCollection);
+  LOG_TRACE("after beginRead");
+  LOGGER_TRACE << "result of beginRead: " << lockResult;
 
   TRI_voc_cid_t cid = _documentCollection->base._cid;
   TRI_doc_mptr_t const document = findDocument(did);
 
+  LOG_TRACE("before endRead");
   _documentCollection->endRead(_documentCollection);
+  LOG_TRACE("after endRead");
 
   // .............................................................................
   // outside read transaction
@@ -511,7 +522,10 @@ bool RestDocumentHandler::readAllDocuments () {
 
   vector<TRI_voc_did_t> ids;
 
-  _documentCollection->beginRead(_documentCollection);
+  LOG_DEBUG("before beginRead");
+  int lockResult = _documentCollection->beginRead(_documentCollection);
+  LOG_DEBUG("after beginRead");
+  LOGGER_TRACE << "result of beginRead: " << lockResult;
 
   TRI_voc_cid_t cid = _documentCollection->base._cid;
 
@@ -537,7 +551,9 @@ bool RestDocumentHandler::readAllDocuments () {
     // necessary so we will always remove the read lock
   }
   
+  LOG_TRACE("before endRead");
   _documentCollection->endRead(_documentCollection);
+  LOG_TRACE("after endRead");
 
   // .............................................................................
   // outside read transaction
@@ -715,7 +731,10 @@ bool RestDocumentHandler::updateDocument () {
   // inside write transaction
   // .............................................................................
 
-  _documentCollection->beginWrite(_documentCollection);
+  LOG_DEBUG("before beginWrite");
+  int lockResult = _documentCollection->beginWrite(_documentCollection);
+  LOG_DEBUG("after beginWrite");
+  LOGGER_TRACE << "result of beginWrite: " << lockResult;
 
   // unlocking is performed in updateJson()
   TRI_voc_rid_t rid = 0;
@@ -860,7 +879,10 @@ bool RestDocumentHandler::deleteDocument () {
   // inside write transaction
   // .............................................................................
 
-  _documentCollection->beginWrite(_documentCollection);
+  LOG_TRACE("before beginWrite");
+  int lockResult = _documentCollection->beginWrite(_documentCollection);
+  LOG_TRACE("after beginWrite");
+  LOGGER_TRACE << "result of beginWrite: " << lockResult;
 
   TRI_voc_rid_t rid = 0;
   TRI_voc_cid_t cid = _documentCollection->base._cid;
diff --git a/arangod/RestHandler/RestVocbaseBaseHandler.cpp b/arangod/RestHandler/RestVocbaseBaseHandler.cpp
index de40357..6e04545 100644
--- a/arangod/RestHandler/RestVocbaseBaseHandler.cpp
+++ b/arangod/RestHandler/RestVocbaseBaseHandler.cpp
@@ -600,7 +600,9 @@ TRI_doc_mptr_t const RestVocbaseBaseHandler::findDocument (string const& doc) {
   // inside read transaction
   // .............................................................................
 
+  LOG_TRACE("before beginRead");
   _documentCollection->beginRead(_documentCollection);
+  LOG_TRACE("after beginRead");
 
   document = _documentCollection->read(_documentCollection, id);
 
@@ -609,7 +611,9 @@ TRI_doc_mptr_t const RestVocbaseBaseHandler::findDocument (string const& doc) {
     _barrier = TRI_CreateBarrierElement(&_documentCollection->_barrierList);
   }
 
+  LOG_TRACE("before endRead");
   _documentCollection->endRead(_documentCollection);
+  LOG_TRACE("after endRead");
 
   // .............................................................................
   // outside read transaction
diff --git a/arangod/V8Server/ApplicationV8.cpp b/arangod/V8Server/ApplicationV8.cpp
index d200d55..80185d3 100644
--- a/arangod/V8Server/ApplicationV8.cpp
+++ b/arangod/V8Server/ApplicationV8.cpp
@@ -1,5 +1,5 @@

 
   v8g->GeneralCursorTempl = v8::Persistent<v8::ObjectTemplate>::New(rt);
 
diff --git a/arangod/V8Server/v8-vocbase.h b/arangod/V8Server/v8-vocbase.h
index fd28c1a..0057617 100644
--- a/arangod/V8Server/v8-vocbase.h
+++ b/arangod/V8Server/v8-vocbase.h
@@ -42,6 +42,18 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 ////////////////////////////////////////////////////////////////////////////////
+/// @brief extracts the collection, but doesn't lock it
+///
+/// it is the caller's responsibility to acquire and release the required locks
+/// the collection must also have the correct status already. don't use this
+/// function if you're unsure about it!
+////////////////////////////////////////////////////////////////////////////////
+
+TRI_sim_collection_t* TRI_ExtractSimpleCollection (v8::Arguments const& argv,
+                                                   TRI_vocbase_col_t const*& collection,
+                                                   v8::Handle<v8::Object>* err);
+
+////////////////////////////////////////////////////////////////////////////////
 /// @brief extracts and locks the collection
 ////////////////////////////////////////////////////////////////////////////////
 
@@ -63,6 +75,7 @@ v8::Handle<v8::Value> TRI_ParseDocumentOrDocumentHandle (TRI_vocbase_t* vocbase,
                                                          TRI_vocbase_col_t const*& collection,
                                                          TRI_voc_did_t& did,
                                                          TRI_voc_rid_t& rid,
+                                                         const bool lock,
                                                          v8::Handle<v8::Value> val);
 
 ////////////////////////////////////////////////////////////////////////////////
diff --git a/arangod/VocBase/compactor.c b/arangod/VocBase/compactor.c
index 2809b17..13ef8fb 100644
--- a/arangod/VocBase/compactor.c
+++ b/arangod/VocBase/compactor.c
@@ -538,10 +538,8 @@ static void CleanupSimCollection (TRI_sim_collection_t* sim) {
 ////////////////////////////////////////////////////////////////////////////////
 
 static void CleanupShadows (TRI_vocbase_t* const vocbase, bool force) {
-  LOG_TRACE("cleaning shadows");
-  
   // clean unused cursors
-  TRI_CleanupShadowData(vocbase->_cursors, SHADOW_CURSOR_MAX_AGE, force);
+  TRI_CleanupShadowData(vocbase->_cursors, (double) SHADOW_CURSOR_MAX_AGE, force);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
diff --git a/arangod/VocBase/shadow-data.c b/arangod/VocBase/shadow-data.c
index b664156..873fc66 100644
--- a/arangod/VocBase/shadow-data.c
+++ b/arangod/VocBase/shadow-data.c
@@ -82,13 +82,14 @@ static TRI_shadow_t* CreateShadow (const void* const data) {
