     @finals[state.id] = state
 
   finalStates: ->
-    out = []
-    for id in finals
-      if finals.hasOwnProperty(id)
-        out.push(finals[id])
-    out
-
+    state for own id, state of finals
 
   test: (sequence) ->
-    state1 = @start
+    state = @start
     current = {}
     next = {}
-    tree = new TreeNode(null, null)
-    current[state1.id] = [state1, tree]
+    tree = new TreeNode()
+    current[state.id] = {state: state, tree: tree}
     for i in [0..sequence.length]
       val = sequence[i]
       next = step(current, val)
-      if next.length == 0
+      if next.size == 0
         return testMatch(current, val)
       else if i == sequence.length - 1
         return testMatch(next, val)


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


  addPath: (array, finalValue) ->
    fsa = @
    state = fsa.start
    ns = null

    for val in array
      arc = state.findArc(val)
      if arc
        state = arc.nextState
      else
        ns = fsa.createState()
        state.connect(val, ns)
        state = ns

    # FIXME: if the state is already final, we duplicate it
    # in the FSM's finalStates array.
    fsa.finalize(state, finalValue)
    fsa

  traverse: (fn) ->
