 /// emitted from `producer` complete.
 public func concat<T, E>(producer: SignalProducer<SignalProducer<T, E>, E>) -> SignalProducer<T, E> {
 	return SignalProducer { observer, disposable in
-		let state = Atomic(ConcatState(observer: observer, disposable: disposable))
+		let state = ConcatState(observer: observer, disposable: disposable)
 
 		producer.startWithSignal { signal, signalDisposable in
 			signal.observe(next: { innerSignalProducer in
 				var shouldStart = true
-				state.modify { (var state) in
+				state.atomic.modify {
 					if !state.latestSignalCompleted {
 						state.queuedSignalProducers.append(innerSignalProducer)
 						shouldStart = false
-						return state
-					} else {
-						return state
 					}
 				}
 				

		self.observer = observer
		self.disposable = disposable
	}

	/// Whether the signal-of-signals has completed yet.
	var selfCompleted = false

}

/// Subscribes to the given signal producer.
private func startNextSignalProducer<T, E>(signalProducer: SignalProducer<T, E>, state: ConcatState<T, E>) {
	let serialDisposable = SerialDisposable()
	let serialDisposableCompositeHandle = state.disposable.addDisposable(serialDisposable)
	state.atomic.modify {
		state.latestSignalCompleted = false
	}
	
	serialDisposable.innerDisposable = signalProducer.start(next: { value in
		sendNext(state.observer, value)
	}, error: { error in
		sendError(state.observer, error)
	}, completed: {
		var nextSignalProducer: SignalProducer<T, E>?
		var isComplete = false

		serialDisposableCompositeHandle.remove()
		state.atomic.modify {
			state.latestSignalCompleted = true
			if state.queuedSignalProducers.isEmpty {
				isComplete = state.isComplete
			} else {
				nextSignalProducer = state.queuedSignalProducers.removeAtIndex(0)
			}
		}
		
		if let nextSignalProducer = nextSignalProducer {
			startNextSignalProducer(nextSignalProducer, state)
		} else if isComplete {
			sendCompleted(state.observer)
		}
	})
}

private final class ConcatState<T, E: ErrorType> {
	/// The observer of a started `concat` producer.
	let observer: Signal<T, E>.Observer

