 else if localStorage?
   docname = window.location.pathname.split('/')[1]
   datastore = new DataStore.LocalStorageLazy docname
-  document = new Document datastore
+  doc = new Document datastore
 
   to_load = null
   if (do datastore.getLastSave) == 0
     to_load = constants.default_data
 
-  create_session document, to_load
+  create_session doc, to_load
 else
   alert('You need local storage support for data to be persisted!')
   datastore = new DataStore.InMemory
-  document = new Document datastore
-  create_session document, constants.default_data
+  doc = new Document datastore
+  create_session doc, constants.default_data
 
 window.onerror = (msg, url, line, col, err) ->
   Logger.logger.error "Caught error: '#{msg}' from  #{url}:#{line}"

  # render when ready
  $(document).ready ->
    View.renderSession session

  # needed for safari
  $pasteHack = $('#paste-hack')
  $pasteHack.focus()
  $(document).on 'click', () ->
    # if settings menu is up, we don't want to blur (the dropdowns need focus)
    if $settingsDiv.hasClass 'hidden'
      # if user is trying to copy, we don't want to blur
      if not window.getSelection().toString()
        $pasteHack.focus()

  $(document).on 'paste', (e) ->
    e.preventDefault()
    text = (e.originalEvent || e).clipboardData.getData('text/plain')
    # TODO: deal with this better when there are multiple lines
    # maybe put in insert mode?
    lines = text.split '\n'
    for line, i in lines
      if i != 0
        do session.newLineAtCursor
      chars = line.split ''
      options = {}
      if session.mode == Modes.modes.INSERT
        options.cursor = {pastEnd: true}
      session.addCharsAtCursor chars, options
    View.renderSession session
    do session.save

  key_handler = new KeyHandler session, key_bindings


  # session
  ####################

  session = new Session doc, {
    bindings: key_bindings
    settings: settings
    mainDiv: $('#view'),
