           .attr('x2', (d) -> d.target.x)
           .attr('y2', (d) -> d.target.y)
 
-      for child in children
-          cell = cellList[child._idx]
-          node = childNodes[child._idx]
-          cell.attr('transform', "translate(#{node.x},#{node.y})")
-              .attr('cy', node.y)
+      for node in children
+          node.cell.attr('transform', "translate(#{node.x},#{node.y})")
 
-    return size
+    return children
 
 
 demo = (tree) ->

drawState = (cell, state) ->
    if state.children?
        g = cell.append('g')
        size = drawChildren(g, state.children)

    else
        size = 100

    r = Math.sqrt(size)

    cell.insert('rect', ':first-child')
        .attr('class', 'border')

      .append('title')
        .text(state.name)

    return node


drawChildren = (g, childStates) ->
    children = []
    childMap = {}

    linkGroup = g.append('g').attr('class', 'linkGroup')

    links = []

    for state in childStates
        cell = g.append('g').attr('class', 'cell')
        child = drawState(cell, state)
        child._idx = children.length
        children.push(child)
        childMap[child.name] = child

    for child in children
        for tr in state.transitions or []
            target = childMap[tr.target]
            links.push({source: child._idx, target: target._idx})

    link = linkGroup
        .selectAll('.link')
        .data(links)
      .enter().append('line')
        .attr('class', 'link')
        .style('stroke-width', (d) -> Math.sqrt(d.value))

    r = 10

    force = d3.layout.force()
        .charge(-r * 6)
        .linkDistance(r * 1.5)

    force
        .nodes(children)
        .links(links)
        .start()

    force.on 'tick', ->
