     }
     
     deinit {
-        if let contexts = contexts {
-            for ctx in contexts {
-                notificationCenter.removeObserver(self, name: NSManagedObjectContextObjectsDidChangeNotification, object: ctx)
-            }
-        } else {
-            notificationCenter.removeObserver(self, name: NSManagedObjectContextObjectsDidChangeNotification, object: nil)
+        for observer in observers {
+            notificationCenter.removeObserver(observer.observer, name: NSManagedObjectContextObjectsDidChangeNotification, object: observer.object)
         }
     }
     

public typealias MOCObserverBlock = (observer: MOCObserver, changes: [String: [NSManagedObjectID]]?) -> ()

public class MOCObserver {
    private let notificationCenter = NSNotificationCenter.defaultCenter()
    
    public private(set) var contexts: [NSManagedObjectContext]?
    
    public var queue: NSOperationQueue
    public var handler: MOCObserverBlock

        self.contexts = contexts
        self.handler = block
        self.queue = NSOperationQueue.currentQueue() ?? NSOperationQueue.mainQueue()
        let observerBlock: (note: NSNotification!) -> Void = { [unowned self] (note) in
            self.managedObjectContextDidChange(note)
        }
        if contexts?.count > 0 {
            for ctx in contexts! {
                let obsObj = notificationCenter.addObserverForName(NSManagedObjectContextObjectsDidChangeNotification, object: ctx, queue: workerQueue, usingBlock: observerBlock)
                observers.append(MOCNotificationObserver(observer: obsObj, object: ctx))
            }
        } else {
            let obsObj = notificationCenter.addObserverForName(NSManagedObjectContextObjectsDidChangeNotification, object: nil, queue: workerQueue, usingBlock: observerBlock)
            observers.append(MOCNotificationObserver(observer: obsObj, object: nil))
        }
        if fireInitially {
            block(observer: self, changes: nil)
