     vm.set_md_and_update_editor(md) if md?
     # render html
     vm.render_html($('#md_html_div'))
+    # save current note guid to local storage
+    localStorageService.set(vm.SETTINGS_KEY.CURRENT_NOTE_GUID, guid)
 
   # TODO prevent multiple duplicated requests
   vm.refresh_all_notes = ->

        }
      }
    }
    return db.open(db_open_option)

  get_db_server_promise: () =>
    console.log('return @db_server_promise')
    return @db_server_promise

  close_db: () =>

    # sync scroll
    scrollSyncor.syncScroll(vm.ace_editor, $('#md_html_div'))

    # get previous note guid from local storage,
    # if exists such note, load it,
    # else make new note
    previous_note_guid = localStorageService.get(vm.SETTINGS_KEY.CURRENT_NOTE_GUID)
    if previous_note_guid? == false
      previous_note_guid = "INVALID_GUID"
    p = noteManager.find_note_by_guid(previous_note_guid).then (note) =>
      if note?
        console.log('got valid previous current note ' + previous_note_guid + '. load...')
        vm.load_note(note.guid)
      else
        console.log('no valid previous current note found. create new note')
        noteManager.make_new_note().then(
          (note) =>
            vm.change_current_note(guid=note.guid, title=note.title, md=note.md)
            console.log('New note made: ' + JSON.stringify(note))
          (error) =>
            alert('make_new_note() failed!')
        ).catch (error) => alert('make new note failed!')
    p.catch (error) => alert('load previous current note failed')

    # get note list
    vm.refresh_all_notes()
