     private static func maintenance() {
         Meow.log("Performing maintenance")
         
-        do {
-            Meow.pool.clean()
-            try Meow.pool.autoSave()
-        } catch {
-            Meow.log("❗ Error while performing maintenance")
-            Meow.log(error)
-            assertionFailure("\(error)")
-        }
+        Meow.pool.clean()
+        Meow.pool.maintenance()
         
         // Schedule next maintenance
         scheduleMaintenance()
     }
     
     private static func scheduleMaintenance() {
-        maintenanceQueue.asyncAfter(deadline: DispatchTime(secondsFromNow: maintenanceInterval), execute: Meow.maintenance)
+        maintenanceQueue.asyncAfter(deadline: DispatchTime(secondsFromNow: maintenanceInterval), flags: .barrier, execute: Meow.maintenance)
     }
     
     /// The ObjectPool is used to hold references to models to link them in-memory

            
            Meow.log("Unpooling \(instance)")
            
            objectPoolMutationQueue.sync {
                storage[instance._id] = nil
                
                // remove if invalidated to free up memory:
                invalidatedObjectIds.remove(instance._id)
            }
        }
        
        /// The amount of pooled objects
        public var count: Int {
            self.clean()
            return objectPoolMutationQueue.sync {
                return storage.count
            }
        }
        
        /// Removes deallocated entries from the pool
        @discardableResult
        public func clean() -> Int {
            return objectPoolMutationQueue.sync {
                var cleanedCount = 0
                
                for (id, val) in storage {
                    if val.instance.value == nil {
                        storage[id] = nil
                        cleanedCount += 1
                    }
                }
                
                return cleanedCount
            }
        }
        
        /// Handles automatically saving models so they don't get lost when the server randomly crashes/shuts down
        fileprivate func autoSave() throws {
            let oldObjects = objectPoolMutationQueue.sync {
                return storage.filter({ $0.value.instantiation.timeIntervalSinceNow < -(minimumAutosaveAge) })
            }
            
            for (_, val) in oldObjects {
                try (val.instance.value as? BaseModel)?.save()
            }
        }
    }

                throw Error.missingOrInvalidValue(key: "_id", expected: ObjectId.self, got: document["_id"])
            }
            
            objectPoolMutationLock.lock()
            let existingInstance: M? = storage[id]?.instance.value as? M
            objectPoolMutationLock.unlock()
            
            if let existingInstance = existingInstance {
                Meow.log("Returning \(existingInstance) from pool")
                return existingInstance
            }
            
            let instantiation: RunningInstantiation = try {
                objectPoolMutationLock.lock()
                defer { objectPoolMutationLock.unlock() }
                
                let instantiation = currentlyInstantiating[id]
                guard instantiation == nil || instantiation!.thread != Thread.current else {
                    throw Meow.Error.infiniteReferenceLoop(type: M.self, id: id)
