      v8::Handle<v8::Object> errorObject = TRI_CreateErrorObject(TRI_ERROR_OUT_OF_MEMORY, "out of memory");
  
      return scope.Close(v8::ThrowException(errorObject));
-@@ -1849,13 +1932,12 @@ static v8::Handle<v8::Value> JS_ExplainAhuacatl (v8::Arguments const& argv) {
+@@ -1849,13 +1948,12 @@ static v8::Handle<v8::Value> JS_ExplainAhuacatl (v8::Arguments const& argv) {
  
    TRI_json_t* explain = 0;
  

+  public:
+    AhuacatlContextGuard (TRI_vocbase_t* vocbase, const string& query) : 
+      _context(0) {
+      _context = TRI_CreateContextAql(vocbase, query.c_str());
+    }
+
+    ~AhuacatlContextGuard () {
+      this->free();
+    }
+
+    void free () {

 // --SECTION--                                                  HELPER FUNCTIONS
 // -----------------------------------------------------------------------------
 
@@ -1048,14 +1114,17 @@ 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);
 
   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 +1132,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 +1143,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 +1154,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 +1163,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 +1372,10 @@ static v8::Handle<v8::Value> JS_DisposeGeneralCursor (v8::Arguments const& argv)
   bool found = TRI_DeleteDataShadowData(vocbase->_cursors, UnwrapGeneralCursor(argv.Holder()));
 
   if (found) {
