var stack = [], push = [].push, token = {}

function Callback (cadence, result) {
    var self = this
    this.cadence = cadence
    this.result = result
    this.callback = callback
    function callback () {
        var vargs = new Array
        for (var i = 0, I = arguments.length; i < I; i++) {
            vargs[i] = arguments[i]
        }
        callbacks.push(self)
        self.cadence.resolveCallback(self.result, vargs)
    }
}

var callbacks = []

function Cadence (self, steps, vargs, callback) {
    this.self = self
    this.finalizers = new Array
    this.steps = steps
    this.callback = callback
    this.index = 0
    this.vargs = vargs
    this.results = new Array
    this.errors = new Array
    this.called = 0
    this.sync = true
    this.waiting = false
    this.cadence = this
}

Cadence.prototype.resolveCallback = function (result, vargs) {
    var error = vargs.shift()
    if (error == null) {
        result.vargs = vargs
    } else {
        this.errors.push(error)
    }
    if (++this.called === this.results.length) {
        if (this.waiting) {
            invoke(this)
        } else {
            this.sync = true
        }
    }
}

Cadence.prototype.createCallback = function () {
    var result = { vargs: [] }, callback

    this.results.push(result)
    this.sync = false

    if (callbacks.length === 0) {
        callback = new Callback(this, result)
    } else {
        callback = callbacks.pop()
        callback.cadence = this
        callback.result = result
    }

    return callback.callback
}

function async () {
    return stack[stack.length - 1].createCallback()
}

async.continue = { token: token, repeat: true }
async.break = { token: token, repeat: false }

function call (fn, self, vargs) {
    try {
        var ret = fn.apply(self, vargs)
    } catch (e) {
        return [ ret, e ]
    }
    return [ ret ]
}

Cadence.prototype.rescue = function () {
    var errors = this.errors, catcher = this.catcher
    this.errors = new Array
    this.results = new Array
    this.catcher = null
    this.called = 0
    this.waiting = true
    var callback = this.createCallback()
    var steps = [ function () { return catcher(async, errors[0], errors) } ]
    var rescue = new Cadence(this.self, steps, this.vargs, callback)
    rescue.waiting = true
    rescue.cadence = this
    invoke(rescue)
}

Cadence.prototype.finalize = function (vargs) {
    if (this.finalizers.length == 0) {
        (this.callback).apply(null, vargs)
    } else {
        var finalizer = this.finalizers.pop()
        execute(this.self, finalizer.steps, finalizer.vargs, function (error) {
            if (error) {
                this.errors.push(error)
                vargs = [ this.errors[0] ]
            }
            this.finalize(vargs)
        }.bind(this))
    }
}

function invoke (cadence) {
    var vargs, steps = cadence.steps
    for (;;) {
        if (cadence.errors.length) {
            if (cadence.catcher) {
                cadence.rescue()
            } else {
                cadence.finalize([ cadence.errors[0] ])
            }
            break
        }

        if (cadence.results.length == 0) {
            vargs = cadence.vargs
            if (vargs[0] && vargs[0].token === token) {
                cadence.cadence.index = vargs.shift().repeat ? 0 : cadence.cadence.steps.length
            }
        } else {
            vargs = []
            for (var i = 0, I = cadence.results.length; i < I; i++) {
                var vargs_ = cadence.results[i].vargs
                for (var j = 0, J = vargs_.length; j < J; j++) {
                    vargs.push(vargs_[j])
                }
            }
            cadence.vargs = vargs
        }

        if (cadence.index === steps.length) {
            if (vargs.length !== 0) {
                vargs.unshift(null)
            }
            if (cadence.finalizers.length === 0) {
                (cadence.callback).apply(null, vargs)
            } else {
                cadence.finalize(vargs)
            }
            break
        }

        var fn = steps[cadence.index++]

        cadence.called = 0
        cadence.results = new Array
        cadence.errors = new Array

        if (Array.isArray(fn)) {
            if (fn.length === 1) {
                cadence.finalizers.push({ steps: fn, vargs: vargs })
                continue
            } else if (fn.length === 2) {
                cadence.catcher = fn[1]
                fn = fn[0]
            } else if (fn.length === 3) {
                var filter = fn
                cadence.catcher = function (async, error) {
                    if (filter[1].test(error.code || error.message)) {
                        return filter[2](async, error)
                    } else {
                        throw error
                    }
                }
                fn = fn[0]
            } else {
                cadence.vargs = [ vargs ]
                continue
            }
        }

        vargs.unshift(async)

        stack.push(cadence)

        var ret = call(fn, cadence.self, vargs)
               // ^^^^

        stack.pop()

        if (ret.length === 2) {
            cadence.errors.push(ret[1])
            cadence.sync = true
        } else if (ret[0] !== void(0)) {
            cadence.vargs = Array.isArray(ret[0]) ? ret[0] : [ ret[0] ]
        }

        if (!cadence.sync) {
            cadence.waiting = true
            break
        }
    }
}

function execute (self, steps, vargs, callback) {
    var cadence = new Cadence(self, steps, vargs, callback)
    invoke(cadence)
}

function hotspot () {
    var I = arguments.length
    var steps = new Array
    for (var i = 0; i < I; i++) {
        steps.push(arguments[i])
    }
    return function () {
        var I = arguments.length
        var vargs = new Array
        for (var i = 0; i < I - 1; i++) {
            vargs.push(arguments[i])
        }
        execute(this, steps, vargs, arguments[i])
    }
}

module.exports = hotspot

@@ -1971,34 +1971,26 @@
    this.
-errors = new Array
+called = 0
 %0A    thi
@@ -2003,32 +2003,60 @@
 lts = new Array%0A
+    this.errors = new Array%0A
     this.catcher
@@ -2063,36 +2063,16 @@
  = null%0A
-    this.called = 0%0A
     this
@@ -2091,49 +2091,8 @@
 rue%0A
-    var callback = this.createCallback()%0A
     
@@ -2219,32 +2219,45 @@
 this.vargs, 
-c
+this.createC
 allback
+()
 )%0A    rescue
@@ -2257,30 +2257,30 @@
  rescue.
-waiting
+cadence
  = t
-rue
+his
 %0A    res
@@ -2279,38 +2279,38 @@
 %0A    rescue.
-cadence
+waiting
  = t
-his
+rue
 %0A    invoke(

Tidy rescue creation.