     @_parent?.removeChild this
 
     for child in @_children
-      child.destroy()
+      child?.destroy()
 
     return @
 

  removeChild: (task) ->
    i = @_children.indexOf task
    if i > -1
      @_children.splice i, 1
      task._parent = null
    return @


      return @
    else
      for child in @_children
        if child?
          task = child.getTaskById id
          return task if task?
      return null

DivSugar.rootTask = new DivSugar.Task('rootTask')
