       @trigger("noBranchPoints")
       deferred.reject()
 
-  deleteBranch : (nodeID) ->
+  deleteBranch : (node) ->
+
+    if node.type != TYPE_BRANCH then return
 
     i = 0
     while i < @branchStack.length
-      if @branchStack[i].id == nodeID
+      if @branchStack[i].id == node.id
         @branchStack.splice(i, 1)
       else
         i++

    deletedNode = @activeNode
    @stateLogger.deleteNode(deletedNode, @activeTree.treeId)

    if deletedNode.type == TYPE_BRANCH
      @deleteBranch(deletedNode.id)
    
    if deletedNode.neighbors.length > 1
      # Need to split tree

      @deleteTree(false)


  deleteTree : (notify, id, deleteBranchesAndComments) ->

    unless @activeNode?
      return

    if notify
      if confirm("Do you really want to delete the whole tree?")
        @reallyDeleteTree(id, deleteBranchesAndComments)
      else
        return
    else
      @reallyDeleteTree(id, deleteBranchesAndComments)


  reallyDeleteTree : (id, deleteBranchesAndComments = true) ->

    unless id
      id = @activeTree.treeId
