         }
     }
 
-    private func append<U>(dispatchQueue: dispatch_queue_t, nextPromise: Promise<U>, onRejected: (NSError -> Void)?) {
+    private func appendR(dispatchQueue: dispatch_queue_t,
+        onRejected: (NSError -> Void)?,
+        nextReject: NSError -> Void)
+    {
         let onRejectedAsync = { (error: NSError) -> Void in
             dispatch_async(dispatchQueue, {
                 onRejected?(error)
-                nextPromise.reject(error)
+                nextReject(error)
             })
         }
 

                })
        }
        
        return promise
    }
}


    }

    public func then<U>(dispatchQueue: dispatch_queue_t, _ onFulfilled: ValueType throws -> Promise<U>, _ onRejected: (NSError -> Void)? = nil) -> Promise<U> {
        let deferred = Promise<U>.deferred()

        dispatch_semaphore_wait(self.mutex, DISPATCH_TIME_FOREVER)
        do {
            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 deferred.promise
    }

    public func then<U>(dispatchQueue: dispatch_queue_t, _ onFulfilled: ValueType throws -> U, _ onRejected: (NSError -> Void)? = nil) -> Promise<U> {
        let deferred = Promise<U>.deferred()

        dispatch_semaphore_wait(self.mutex, DISPATCH_TIME_FOREVER)
        do {
            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 deferred.promise
    }

    private func appendP<U>(dispatchQueue: dispatch_queue_t,
