     if content
       length = @length++
       nodes = @nodes
-      nodes[length] = 
+      #objects can onyl be part of one heap at a time, bad things happen otherwise
+      content._heapNode = nodes[length] = 
         content: content
         value: value
+        index: length
       @bubbleUp(length)
 
   update: (content, value)->
-    if content?
+    if content? && content._heapNode?
       nodes = @nodes
-      for i, node of nodes
-        if content == node.content
-          break
+      swap = content._heapNode
 
-      swap = node
+      i = swap.index
       nodes[i] = nodes[0]
+      nodes[i].index = i
       nodes[0] = swap
+      nodes[0].index = 0
       swap.value = value
 
       sift = 0

        lesser = if nodes[left].value > nodes[right].value then right else left
        if node.value > nodes[lesser].value
          nodes[i] = nodes[lesser]
          nodes[lesser] = node
          return lesser
      else if node.value > nodes[left].value
        nodes[i] = nodes[left]
        nodes[left] = node
        return left
    return null

  heapify: ()->
    for i in [0..@nodes.length-1]
      @siftDown(i)

module.exports = Heap
  nodes: null
  length: 0
  constructor: (options)->
    #if !options?
      #options = {}
    #@nodes = options.nodes || []
    #@heapify()
    @nodes = []

  pop: ()->
    if @length > 0
