     /// Behavior is matched in order, i.e., the function associated with the
     /// first matcher that matches the given interaction is invoked.
     public func invoke(interaction: Interaction) -> ReturnValue? {
-        for (_, matcher, returnValueForInteraction) in behavior {
-            if matcher.matches(interaction) {
-                return returnValueForInteraction(interaction)
+        for (_, behavior) in behaviors {
+            if behavior.matcher.matches(interaction) {
+                return behavior.handler(interaction)
             }
         }
 

/// A stub that, when invoked, returns a value based on the set up behavior, or,
/// if an interaction is unexpected, returns nil.
public final class Stub<Interaction, ReturnValue> {
    private typealias Behavior = (identifier: UInt, matcher: Matcher<Interaction>, returnValueForInteraction: Interaction -> ReturnValue)

    private var currentIdentifier: UInt = 0
    private var behavior: [Behavior] = []

    /// Initializes a new stub.
    public init() {

    /// an interaction.
    ///
    /// Returns a disposable that, when disposed, removes this behavior.
    public func on<M: MatcherConvertible where M.ValueType == Interaction>(matcher: M, invoke handler: Interaction -> ReturnValue) -> Disposable {
        let identifier = currentIdentifier++
        behaviors.append(identifier: identifier, behavior: Behavior(matcher: matcher, handler: handler))

        return Disposable { [weak self] in
            for var index = 0; index < self?.behaviors.count; index++ {
                if self?.behaviors[index].identifier == identifier {
                    self?.behaviors.removeAtIndex(index)
                    return
                }
            }
