     }
     
     internal func fulfill(_ value: T) {
-        guard case .pending = self.state else { return }
-        self.syncQueue.sync { self.state = .fulfilled(value) }
+        guard case .pending = state else { return }
+        self.syncQueue.sync { state = .fulfilled(value) }
         self.syncQueue.async {
             self.executeDeferedCompletionHandlers()
         }
     }
     
     internal func reject(_ error: Error) {
-        guard case .pending = self.state else { return }
-        self.syncQueue.sync { self.state = .rejected(error) }
+        guard case .pending = state else { return }
+        self.syncQueue.sync { state = .rejected(error) }
         self.syncQueue.async {
             self.executeDeferedCompletionHandlers()
         }

    }

    @discardableResult
    open func finally(_ context: @escaping ExecutionContext = defaultExecutionContext, handler: @escaping (Void) -> Void) -> Future<T> {
        self.syncQueue.async {
            let completionHandler = FutureCompletionHandler<T>.finally(task: handler, context: context)
            switch self.state {
            case .pending:
                self.deferCompletionHandler(completionHandler)

    }
    
    fileprivate func executeDeferedCompletionHandlers() {
        self.stateHandlers.forEach(executeCompletionHandler)
        self.stateHandlers = []
    }

    fileprivate func executeCompletionHandler(_ handler: FutureCompletionHandler<T>) {
        switch (handler, state) {
        case (.success(let successHandler, let queue), .fulfilled(let value)):
            queue.async { successHandler(value) }
        case (.failure(let failureHandler, let queue), .rejected(let error)):
            queue.async { failureHandler(error) }
        case (.finally(let finalHandler, let queue), _) where !self.state.isPending:
            queue.async { finalHandler() }
        default: break
        }
    }
    
    fileprivate func deferCompletionHandler(_ handler: FutureCompletionHandler<T>) {
        stateHandlers.append(handler)
    }
    
    @discardableResult
    public func onSuccess(on queue: DispatchQueue = DispatchQueue.main,
                          successHandler: @escaping (T) -> Void) -> Future<T> {

        syncQueue.async {
            let completionHandler = FutureCompletionHandler.success(task: successHandler, queue: queue)
            switch self.state {
            case .pending:
                self.deferCompletionHandler(completionHandler)
