       window.removeAllListeners 'close'
       window.close()
 
-    ipc.on 'open-folder', ->
+    ipc.on 'open-folder', =>
       currentWindow = BrowserWindow.getFocusedWindow()
-      dialog.openFolder currentWindow, {}, (result, paths...) =>
-        new AtomWindow
-          bootstrapScript: 'window-bootstrap',
-          resourcePath: resourcePath
+      dialog.openFolder currentWindow, {}, (result, paths...) => @createAtomWindow()
+
+  createAtomWindow: ->
+    new AtomWindow
+      bootstrapScript: 'window-bootstrap',
+      resourcePath: resourcePath
 
 class AtomWindow
   @windows = []

    @setupJavaScriptArguments()
    @buildApplicationMenu()
    @handleEvents()

  setupJavaScriptArguments: ->
    app.commandLine.appendSwitch 'js-flags', '--harmony_collections'

  setupNodePaths()
  atomApplication = new AtomApplication

delegate.browserMainParts.preMainMessageLoopRun = bootstrapApplication

app = require 'app'
