diff --git a/plugins/tabs/tabs.coffee b/plugins/tabs/tabs.coffee
index 11095f1a0..2301aa3df 100644
--- a/plugins/tabs/tabs.coffee
+++ b/plugins/tabs/tabs.coffee
@@ -47,7 +47,7 @@ class Tabs extends Pane
name = _.last path.split '/'
$('#tabs ul .active').removeClass()
- $('#tabs ul li:last').after """
+ $('#tabs ul').append """
#{name}
"""
$('#tabs ul li:last').addClass 'active'
@@ -57,10 +57,9 @@ class Tabs extends Pane
nextTab = activeTab.next()
nextTab = activeTab.prev() if nextTab.length == 0
- if nextTab.length != 0
- @editor.deleteSession activeTab.data 'path'
- activeTab.remove()
- @switchToTab nextTab
+ @editor.deleteSession activeTab.data 'path'
+ activeTab.remove()
+ @switchToTab nextTab if nextTab.length != 0
hideTabs: ->
$('#tabs').parents('.pane').remove()
diff --git a/plugins/tabs/tabs.html b/plugins/tabs/tabs.html
index 6b7ddca83..aeaf485d9 100644
--- a/plugins/tabs/tabs.html
+++ b/plugins/tabs/tabs.html
@@ -1,6 +1,5 @@
diff --git a/src/editor.coffee b/src/editor.coffee
index 734138ea4..e31dbccd0 100644
--- a/src/editor.coffee
+++ b/src/editor.coffee
@@ -100,8 +100,10 @@ class Editor extends Pane
@ace.setSession @sessions[path]
deleteSession: (path) ->
- @filename = null if path is @filename
+ if path is @filename
+ @filename = null
delete @sessions[path]
+ @ace.setSession @newSession()
newSession: (code) ->
doc = new EditSession code or ''