 
 public func takeUntil<T, U>(triggerStream: Stream<U>)(upstream: Stream<T>) -> Stream<T>
 {
-    var upstreamAutoCanceller: AutoCanceller? = nil
-    var triggerAutoCanceller: AutoCanceller? = nil
-    
     return Stream<T> { [weak triggerStream] progress, fulfill, reject, configure in
         
         if let triggerStream = triggerStream {
-            
-            _bindToUpstream(upstream, fulfill, reject, configure)
-            
-            upstream.react(&upstreamAutoCanceller) { value in
+        
+            var upstreamCanceller: Canceller? = nil
+            var triggerCanceller: Canceller? = nil
+            let combinedCanceller = Canceller {
+                upstreamCanceller?.cancel()
+                triggerCanceller?.cancel()
+            }
+            _bindToUpstream(upstream, fulfill, reject, configure, combinedCanceller)
+            
+            upstream.react(&upstreamCanceller) { value in
                 progress(value)
             }
 
             let cancelError = _RKError(.CancelledByTriggerStream, "Stream=\(upstream.name) is cancelled by takeUntil(\(triggerStream.name)).")
             
-            triggerStream.react(&triggerAutoCanceller) { [weak upstream] _ in
+            triggerStream.react(&triggerCanceller) { [weak upstream] _ in
                 if let upstream_ = upstream {
                     upstream_.cancel(error: cancelError)
                 }

-> Stream<U>
{
    return Stream<U> { progress, fulfill, reject, configure in
        _bindToUpstream(upstream, nil, nil, configure)
        customizeClosure(upstream: upstream, progress: progress, fulfill: fulfill, reject: reject)
    }.name("\(upstream.name)-customize")
}


public func distinct<H: Hashable>(upstream: Stream<H>) -> Stream<H>
{
    return Stream<H> { progress, fulfill, reject, configure in
        
        var canceller: Canceller? = nil
        _bindToUpstream(upstream, fulfill, reject, configure, canceller)
        
        var usedValueHashes = Set<H>()
        
        upstream.react(&canceller) { value in
            if !usedValueHashes.contains(value) {
                usedValueHashes.insert(value)
                progress(value)
