     }
 
     public func then<U>(dispatchQueue: dispatch_queue_t, _ onFulfilled: ValueType throws -> Promise<U>, _ onRejected: (NSError -> Void)? = nil) -> Promise<U> {
-        let (nextPromise, nextFulfill, nextReject) = Promise<U>.deferred()
+        let deferred = Promise<U>.deferred()
 
         dispatch_semaphore_wait(self.mutex, DISPATCH_TIME_FOREVER)
         do {
-            self.appendP(dispatchQueue, onFulfilled: onFulfilled, nextFulfill: nextFulfill, nextReject: nextReject)
-            self.append(dispatchQueue, nextPromise: nextPromise, onRejected: onRejected)
+            self.appendP(dispatchQueue, onFulfilled: onFulfilled, nextFulfill: deferred.fulfill, nextReject: deferred.reject)
+            self.appendR(dispatchQueue, onRejected: onRejected, nextReject: deferred.reject)
         }
         dispatch_semaphore_signal(self.mutex)
 
-        return nextPromise
+        return deferred.promise
     }
 
     public func then<U>(dispatchQueue: dispatch_queue_t, _ onFulfilled: ValueType throws -> U, _ onRejected: (NSError -> Void)? = nil) -> Promise<U> {
-        let nextPromise = Promise<U>()
+        let deferred = Promise<U>.deferred()
 
         dispatch_semaphore_wait(self.mutex, DISPATCH_TIME_FOREVER)
         do {
-            self.append(dispatchQueue, nextPromise: nextPromise, onFulfilled: onFulfilled)
-            self.append(dispatchQueue, nextPromise: nextPromise, onRejected: onRejected)
+            self.appendF(dispatchQueue, onFulfilled: onFulfilled, nextFulfill: deferred.fulfill, nextReject: deferred.reject)
+            self.appendR(dispatchQueue, onRejected: onRejected, nextReject: deferred.reject)
         }
         dispatch_semaphore_signal(self.mutex)
 
-        return nextPromise
+        return deferred.promise
     }
 
     private func appendP<U>(dispatchQueue: dispatch_queue_t,

                            values.append(value)

                            if values.count == promises.count {
                                promise.fulfill(values)
                                pending = false
                                values.removeAll(keepCapacity: false)
                            }

    }

    class func resolve(value: ValueType) -> Promise<ValueType> {
        return Promise<ValueType> { (fulfill, _) -> Void in
            fulfill(value)
        }
    }

    /// Create a promise that is rejected with given error.
    class func reject(error: NSError) -> Promise<ValueType> {
        return Promise<ValueType> { (_, reject) -> Void in
            reject(error)
        }
    }
}

