 cmds = require("../commands")
 util = require("../util")
 
-{fatalError, infoMsg, programDone, runCommand, callCommand, confirmPrompt} = util
-colors = data = schemes = schemesFile = scheme = currentScheme = autoCompact = recurseWarn = undefined
+{fatalError, infoMsg, programDone, ensureDirExists, runCommand, callCommand, confirmPrompt} = util
+colors = schemeDir = schemes = dataFile = data = schemeFile =
+  scheme = currentScheme = autoCompact = recurseWarn = undefined
 
 #
 # load schemes and configuation
 #
 
-saveSchemes = () ->
-  util.saveJsonFile(schemesFile, data)
-
-initSchemesObj = () ->
+saveSchemeConfig = () ->
+  util.saveJsonFile(dataFile, data)
+
+saveCurrentScheme = () ->
+  util.saveJsonFile(schemeFile, scheme)
+
+initConfigObj = () ->
   return {
     currentScheme: "default"
     autoCompact: true
     recurseWarn: 10
-    schemes: {
-      default:
-        next: 0
-        slots: {}
-    }
+    schemes: ["default"]
   }
 
-initalizeScheme = (scheme) ->
-  schemes[scheme] =
+initSchemeObj = () ->
+  return {
     next: 0
     slots: {}
-  saveSchemes()
+  }
 
 loadSchemes = () ->
-  data = util.loadJsonFile(schemesFile, initSchemesObj)
+  ensureDirExists schemeDir
+  data = util.loadJsonFile(dataFile, initConfigObj)
   {currentScheme, autoCompact, recurseWarn, schemes} = data
-  scheme = schemes[currentScheme]
-  return if _.isObject(scheme)
-  console.error chalk.yellow "currentScheme is missing from schemes.json, setting to 'default' scheme"
-  initalizeScheme "default" unless _.isObject(schemes["default"])
-  currentScheme = "default"
-  scheme = schemes[currentScheme]
+  unless _.contains schemes, currentScheme
+    schemes.push currentScheme
+    saveSchemeConfig()
+
+  schemeFile = path.join(schemeDir, "#{currentScheme}.json")
+  scheme = util.loadJsonFile(schemeFile, initSchemeObj)
 
 util.emitter.on "config:loaded", (config, dataDir) ->
-  schemesFile = path.join(dataDir, "schemes.json")
+  schemeDir = path.join(dataDir, "schemes")
+  dataFile = path.join(dataDir, "schemes.json")
   {colors} = config
 
 #

    for obj, idx in slotsArray
      scheme.slots[idx] = obj.slot
    scheme.next = parseInt(_.max(_.keys(scheme.slots))) + 1
    saveSchemes()
    programDone()

cmds.extend schemeCommands

      doAutoCompact() if autoCompact
      scheme.next = parseInt(_.max(_.keys(scheme.slots))) + 1
      schemeMsg chalk.green "saved #{paths.length} directories"
      saveCurrentScheme()
      programDone()

    if (paths.length > recurseWarn)
