         #if os(iOS)
 
             if AKSettings.enableRouteChangeHandling {
-                NotificationCenter.default.addObserver(forName: .AVAudioSessionRouteChange,
-                                                       object: nil,
-                                                       queue: OperationQueue.main,
-                                                       using: { (notification) in
-                                                        AudioKit.restartEngineAfterRouteChange(notification)
+
+                let routeChangeObserver = NotificationCenter.default.addObserver(forName: .AVAudioSessionRouteChange,
+                                                                                 object: nil,
+                                                                                 queue: OperationQueue.main,
+                                                                                 using: { (notification) in
+                                                                                    AudioKit.restartEngineAfterRouteChange(notification)
                 })
+                notificationObservers.append(routeChangeObserver)
 
             }
 
             if AKSettings.enableCategoryChangeHandling {
-                NotificationCenter.default.addObserver(forName: .AVAudioEngineConfigurationChange,
-                                                       object: engine,
-                                                       queue: OperationQueue.main,
-                                                       using: { (notification) in
-                                                        AudioKit.restartEngineAfterConfigurationChange(notification)
+                let configurationChangeObserver = NotificationCenter.default.addObserver(forName: .AVAudioEngineConfigurationChange,
+                                                                                         object: engine,
+                                                                                         queue: OperationQueue.main,
+                                                                                         using: { (notification) in
+                                                                                            AudioKit.restartEngineAfterConfigurationChange(notification)
                 })
+                notificationObservers.append(configurationChangeObserver)
             }
             try updateSessionCategoryAndOptions()
             try AVAudioSession.sharedInstance().setActive(true)

    @objc static var shouldBeRunning = false

    @objc static var finalMixer = AKMixer()

    /// An audio output operation that most applications will need to use last
    @objc open static var output: AKNode? {

        // Stop the engine.
        engine.stop()
        shouldBeRunning = false

        notificationObservers.forEach { (observer) in
            NotificationCenter.default.removeObserver(observer)
        }

        #if os(iOS)
        do {
            try AVAudioSession.sharedInstance().setActive(false)
