     data = []
     rootDocs = _.filter docs, (doc) => !@hasParent(doc)
     rootDocs.sort(@compareDocs)
+    args = {visited: {count: 0, ids: {}}}
     _.each rootDocs, (doc) =>
-      datum = @docToNodeData(doc)
+      datum = @docToNodeData(doc, args)
       data.push(datum)
-    data
+    Setter.merge {data: data}, args
 
   compareDocs: (docA, docB) ->
     if docA.name < docB.name then -1 else 1

  uncheckNode: uncheckNode
  setCheckedIds: setCheckedIds
  getCheckedIds: getCheckedIds
  uncheckAll: uncheckAll
  toggleChecked: toggleChecked
  addChecked: addChecked
  removeChecked: removeChecked

    unless @collection
      throw new Error('No collection provided when creating tree data')
  
  getChildren: (doc, args) ->
    args ?= {}
    # Search for root document if doc is undefined
    id = doc?._id ? null
    children = @collection.find({parent: id}).fetch()
    children.sort(@compareDocs)

    children
  
  hasChildren: (doc) -> @getChildren(doc).length == 0
