         
         /// Turns the `instance` into a ghost. It will not be saved again.
         public func ghost(_ instance: BaseModel) {
-            ghosts.insert(ObjectIdentifier(instance))
+            objectPoolMutationQueue.async {
+                self.ghosts.insert(ObjectIdentifier(instance))
+            }
         }
         
         public func isGhost(_ instance: BaseModel) -> Bool {
-            return ghosts.contains(ObjectIdentifier(instance))
+            return objectPoolMutationQueue.sync {
+                return ghosts.contains(ObjectIdentifier(instance))
+            }
         }
         
         /// Instantiates a model from a Document unless the model is alraedy in-memory

        
        /// Saves an object after being deinitialized
        public func handleDeinit<M: BaseModel>(_ instance: M) {
            ghosts.remove(ObjectIdentifier(instance))
            
            do {
                if !invalidatedObjectIds.contains(instance._id) {
                    try instance.save()
                }
            } catch {

        }
        
        internal func updateHash(for instance: BaseModel, with newHash: Int?) {
            // we don't return any value here, and the pool is accessed only from this queue, so this is a safe async operation
            objectPoolMutationQueue.async {
                self.storage[instance._id]?.hash = newHash
            }
        }
        
        /// Invalidates the given ObjectId. Called when removing an object
        internal func invalidate(_ id: ObjectId) {
            // we don't return any value here, and the pool is accessed only from this queue, so this is a safe async operation
            objectPoolMutationQueue.async {
                // remove the instance from the pool
                self.storage[id] = nil
                self.invalidatedObjectIds.insert(id)
            }
        }
        
        /// Frees an objectId fromthe unsavedObjectIds
        public func free(_ id: ObjectId) {
            // we don't return any value here, and the pool is accessed only from this queue, so this is a safe async operation
            objectPoolMutationQueue.async {
                if let index = self.unsavedObjectIds.index(of: id) {
                    Meow.log("Unregistering ObjectId \(id)")
                    self.unsavedObjectIds.remove(at: index)
                }
            }
        }
