      @root = options.root
      @sidenotes = options.sidenotes
 
-    getBreakCost: (node, parent = false) ->
+    getBreakCost: (node) ->
+     if @breakCostMap[node.id]?
+      return @breakCostMap[node.id]
+
      if node.parent()?
       cost = @getBreakCost node.parent(), true
      else

     for i in @mainNodes
      @broken.push INF
      @nextBreak.push null

     n = @mainNodes.length - 1
     while n >= 1

      cost = 0

     if BREAK_COST[node.type]?
      @breakCostMap[node.id] = cost + BREAK_COST[node.type]
     else if node.type is 'section'
      @breakCostMap[node.id] = cost + 100 * (node.level - 2)
     else
      throw new Error 'Unknown type'

     return @breakCostMap[node.id]


    getOffsetTop: (elem, parent) ->
