     index = cell_index cell
     cell.$el.remove()
     cell.notebook.cells.splice index, 1
+    cell.active = false
 
   hide_cell = (cell) ->
     cell.visible = false
     cell.$el.hide()
 
   insert_cell = (cell, position={}) ->
-    if position.before?
+    if position.before?.active
       offset = 0
       current_cell = position.before
       current_cell.$el.before cell.$el
-    else if position.after?
+    else if position.after?.active
       offset = 1
       current_cell = position.after
       current_cell.$el.after cell.$el


  clear_notebook = (notebook) ->
    notebook.$document.empty()
    notebook.cells.length = 0

  cell_index = (cell) ->

    cell =
      type: 'input'
      $el: $el
      visible: true
      active: true
      notebook: notebook
      used: false
      editor: editor
