         scheme.slots = {}
         for obj, idx in slotsArray
           scheme.slots[idx] = obj.slot
-        fs.writeFileSync(schemeFile, JSON.stringify(scheme), "utf8")
-        return 0
+        saveDataFile()
+        programDone()
 
     initialize()
-    #util = require 'util'
-    #console.log "#{arguments} : #{util.inspect(arguments)}"
     commands[cmd].apply(this, arguments);
 
 commander

path = require('path')
_ = require('lodash')

runCommand = (cmd) ->
  return () ->
    # make these variables available outside of initialize scope
    dataDir = currentSchemeFile = currentScheme = schemeFile = commands = undefined

    initialize = () ->
      dataDir = process.env.QDHOME ? path.join(process.env.HOME, ".quick-dir")
      fs.mkdirSync(dataDir) unless fs.existsSync(dataDir)
      currentSchemeFile = path.join(dataDir, "currentScheme")
      currentScheme = null
      if fs.existsSync(currentSchemeFile)
        currentScheme = fs.readFileSync(currentSchemeFile, 'utf8')
        schemeFile = path.join(dataDir, "#{currentScheme}.scheme")
      else
        commands.changeScheme "default"

    #prompt.message = "(crypto-pass)"
    #cacheFile = (commander.config ? commander.config : path.join(getUserHome(), ".crypto-pass"));

    commands =
      printCurrentScheme: () ->
        console.log currentScheme
        programDone()

      changeScheme: (name) ->
        commands.printCurrentScheme() unless name?
        programDone() if name is currentScheme

        data.currentScheme = currentScheme = name
        console.log "changing scheme to #{chalk.cyan name}"
        if _.isObject(data.schemes[name])
          saveDataFile()
        else
          console.log chalk.grey "initializing empty scheme object"
          initalizeScheme name
        programDone()

      listSlots: () ->
        schemeMsg "listing slots"
        console.log "------------------------------"
        slots = _.sortBy(_.pairs(scheme.slots), (pair) -> parseInt(pair[0]))
        for pair in slots
          console.log "#{chalk.yellow pair[0]}\t#{chalk.grey pair[1]}"
        programDone()

      getSlot: (idx) ->
        idx = parseInt(idx)
        fatalError "argument <idx> should be a whole number" unless _.isNumber(idx) and not _.isNaN(idx) and idx >= 0
        _path = scheme.slots[idx]
        fatalError "path #{_path} is not a string" unless _.isString(_path)
        console.log _path
        programDone()

      saveSlot: (idx, _path) ->
        idx = parseInt(idx)
        fatalError "argument <idx> should be a whole number" unless _.isNumber(idx) and not _.isNaN(idx) and idx >= 0
        _path = process.cwd() unless _.isString(_path)
        fatalError "path #{_path} does not exist" unless fs.existsSync _path
        scheme.slots[idx] = _path
        schemeMsg "saving slot #{chalk.yellow idx} as #{chalk.grey _path}"
        saveDataFile()
        programDone()

      clearSlots: () ->
        schemeMsg chalk.yellow "clearing all slots"
        scheme.slots = {}
        saveDataFile()
        programDone()

      compactSlots: () ->
        schemeMsg "compacting slot idx numbers"
        slotsArray = []
        for idx, slot of scheme.slots
          slotsArray.push
