     @keysRef.on "child_removed", (snapshot) =>
       data = snapshot.val()
       return unless data
-
       {indexKey} = data
-      for pane in @tabView.panes
-        if pane?.getOptions().indexKey is indexKey
+
+      for pane in @tabView.panes when pane
+        paneIndexKey = pane.getOption "indexKey"
+        if paneIndexKey is indexKey
           @tabView.removePane pane
+          delete @openIndexes[paneIndexKey]
 
   bindRemoteEvents: ->
     @listenPaneDidShow()


    @tabView.on "PaneAdded", (pane) =>
      pane.getHandle().on "click", =>
        paneOptions = pane.getOptions()
        @workspace.addToHistory
          message    : "$0 switched to #{paneOptions.title}"
          by         : KD.nick()
          data       :
            title    : paneOptions.title
            indexKey : paneOptions.indexKey

        @indexRef.set
          indexKey   : pane.getOptions().indexKey
          by         : KD.nick()

  addNewTab: ->
    @createPlusHandleDropDown()

    super options, data

    @createElements()
    @openIndexes = {}

    @keysRef     = @workspaceRef.child "keys"
    @indexRef    = @workspaceRef.child "index"
    @requestRef  = @workspaceRef.child "request"
    @stateRef    = @workspaceRef.child "state"

    @listenChildRemovedOnKeysRef()
    @listenRequestRef()
