             
             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()
                 }
             }

class SwitchSink<S: ObservableType, O: ObserverType where S.E == O.Element> : Sink<O>, ObserverType {
    typealias Element = S
    typealias Parent = Switch<S>
    
    typealias SwitchState = (
        subscription: SingleAssignmentDisposable,
        innerSubscription: SerialDisposable,
        stopped: Bool,
        latest: Int,
        hasLatest: Bool
    )
    
    let parent: Parent
    
    var lock = NSRecursiveLock()
    var switchState: SwitchState
    
    init(parent: Parent, observer: O, cancel: Disposable) {
        self.parent = parent
        self.switchState = (
                subscription: SingleAssignmentDisposable(),
                innerSubscription: SerialDisposable(),
                stopped: false,
                latest: 0,
                hasLatest: false
        )
        super.init(observer: observer, cancel: cancel)
    }
    
    func run() -> Disposable {
        let subscription = self.parent.sources.subscribeSafe(self)
        let switchState = self.switchState
        switchState.subscription.disposable = subscription
        return CompositeDisposable(switchState.subscription, switchState.innerSubscription)
    }
    
    func on(event: Event<Element>) {
        switch event {
        case .Next(let observable):
            let latest: Int = self.lock.calculateLocked {
                self.switchState.hasLatest = true
                self.switchState.latest = self.switchState.latest &+ 1
                return self.switchState.latest
            }
            
            let d = SingleAssignmentDisposable()
            self.switchState.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 {
                trySendError(observer, error)
                self.dispose()
            }
        case .Completed:
            self.lock.performLocked {
                self.switchState.stopped = true
                
                self.switchState.subscription.dispose()
                
                if !self.switchState.hasLatest {
                    trySendCompleted(observer)
                    self.dispose()
                }
            }

    
    func on(event: Event<Element>) {
        return parent.lock.calculateLocked {
            
            switch event {
            case .Next: break
