             
             switch event {
             case .Next:
-                trySend(observer, event)
+                observer?.on(event)
             case .Error:
-                trySend(observer, event)
+                observer?.on(event)
                 self.parent.dispose()
             case .Completed:
-                parent.switchState.hasLatest = false
-                if switchState.stopped {
-                    trySend(observer, event)
+                parent.hasLatest = false
+                if parent.stopped {
+                    observer?.on(event)
                     self.parent.dispose()
                 }
             }

            case .Completed: self._self.dispose()
            }
            
            if switchState.latest != self.id {
                return
            }
           

class SwitchSink<S: ObservableType, O: ObserverType where S.E == O.Element> : Sink<O>, ObserverType {
    typealias Element = S
    typealias Parent = Switch<S>

    let subscriptions: SingleAssignmentDisposable = SingleAssignmentDisposable()
    let innerSubscription: SerialDisposable = SerialDisposable()
    let parent: Parent
    
    var lock = NSRecursiveLock()
    
    // state
    var stopped = false
    var latest = 0
    var hasLatest = false
    
    init(parent: Parent, observer: O, cancel: Disposable) {
        self.parent = parent
        
        super.init(observer: observer, cancel: cancel)
    }
    
    func run() -> Disposable {
        let subscription = self.parent.sources.subscribeSafe(self)
        subscriptions.disposable = subscription
        return CompositeDisposable(subscriptions, innerSubscription)
    }
    
    func on(event: Event<Element>) {
        switch event {
        case .Next(let observable):
            let latest: Int = self.lock.calculateLocked {
                hasLatest = true
                self.latest = self.latest &+ 1
                return self.latest
            }
            
            let d = SingleAssignmentDisposable()
            innerSubscription.disposable = d
               
            let observer = SwitchSinkIter(parent: self, id: latest, _self: d)
            let disposable = observable.subscribeSafe(observer)
            d.disposable = disposable
        case .Error(let error):
            self.lock.performLocked {
                observer?.on(.Error(error))
                self.dispose()
            }
        case .Completed:
            self.lock.performLocked {
                self.stopped = true
                
                self.subscriptions.dispose()
                
                if !self.hasLatest {
                    observer?.on(.Completed)
                    self.dispose()
                }
            }
