diff --git a/include/caosdb/entity.h b/include/caosdb/entity.h
index 3cd8f14d143ee280bd5998c4bd954d0d2dd6aec4..b2cd0a2a6968967e1b3c4c642b5b98223e3e2e9c 100644
--- a/include/caosdb/entity.h
+++ b/include/caosdb/entity.h
@@ -203,20 +203,21 @@ protected:
    */
   inline auto Remove(int index) -> void {
     this->wrapped->DeleteSubrange(index, 1);
-    cache.clear();
-    // if (cache.count(index) > 0) {
-    // cache.erase(index);
-    //}
-
-    //// shift all indices in the cache above index (such that the values do not
-    //// get deleted/copied because this could destroy pointers (c-interface).
-    // for (int i = index + 1; i < size(); i++) {
-    // if (cache.count(i) > 0) {
-    // auto handle = cache.extract(i);
-    // handle.key()--;
-    // cache.insert(std::move(handle));
-    //}
-    //}
+    if (cache.count(index) > 0) {
+      cache.erase(index);
+    }
+
+    // shift all indices in the cache above index (such that the values do not
+    // get deleted/copied because this could destroy pointers (c-interface).
+    for (int i = index + 1; i < size(); i++) {
+      if (cache.count(i) > 0) {
+        auto handle = cache.extract(i);
+        handle.key()--;
+        cache.insert(std::move(handle));
+      }
+    }
+    // this is possible because cache is an ordered map
+    cache.erase(cache.find(size()), cache.end());
   }
 
   inline auto Clear() noexcept -> void { this->wrapped->Clear(); }