 
 step = (current, val) ->
   next = {size: 0}
-  for own id, thing of current when id != "size"
-    state = thing[0]
-    state.arcs.forEach (arc) ->
+  for own key, thing of current when key != "size"
+    thing.state.arcs.forEach (arc) ->
       if arc.test(val)
-        leaf = new TreeNode(thing[1], val)
+        node = new TreeNode(thing.tree, val)
         if arc.nextState.final
-          leaf.final = true
+          node.final = true
         else
           null
-        next[arc.nextState.id] = [arc.nextState, leaf]
+        next[arc.nextState.id] = {state: arc.nextState, tree: node}
         next.size++
   next
 

    @finals[state.id] = state

  finalStates: ->
    out = []
    for id in finals
      if finals.hasOwnProperty(id)
        out.push(finals[id])
    out


  test: (sequence) ->
    state1 = @start
    current = {}
    next = {}
    tree = new TreeNode(null, null)
    current[state1.id] = [state1, tree]
    for i in [0..sequence.length]
      val = sequence[i]
      next = step(current, val)
      if next.length == 0
        return testMatch(current, val)
      else if i == sequence.length - 1
        return testMatch(next, val)


  formatTest: (val) ->
    if typeof(val) == "function"
      "<lambda>"
    else if val == true
      return "<epsilon>"
    else
