       if (SUBKEY_SEPS[1].indexOf(c) >=0) then return i
       --i
     return -1
-  @encode = (aPath, aKey, aSeperator, dontEscapeSeperator)->
-    keyIsStr = isString(aKey) and aKey.length isnt 0
+  @encode =encode = (aPath, aKey, aSeperator, dontEscapeSeperator)->
+    keyIsStr = isString(aKey) and aKey.length > 0
     hasSep   = !!aSeperator
     aSeperator = SUBKEY_SEP unless aSeperator
     if keyIsStr
-      if hasSep && key[0] == aSeperator then key = key.substring(1)
-      key = escapeString(key)
+      if hasSep && aKey[0] == aSeperator then aKey = aKey.substring(1)
+      aKey = escapeString(aKey)
     if dontEscapeSeperator is true
       aSeperator = PATH_SEP + aSeperator if hasSep and aSeperator isnt PATH_SEP
       hasSep = false

        aSeperator = PATH_SEP + aSeperator
    else if keyIsStr
      #try to find the separator on the key
      i = SUBKEY_SEPS[0].indexOf(key[0], 1)
      if i > 0
          vSeperator = PATH_SEP + SUBKEY_SEPS[1][i]
          key = key.substring(1)
    #console.log("codec.encode:",path.join(e[0]) + vSeperator + key)
    #TODO: I should encode with path.join(e[0], vSeperator + key)) simply in V8.
    #      all separators are same now.

      aPath = ""
    else
      aPath = PATH_SEP
    aPath + aSeperator + aKey

  #return [path, key, separator, realSeparator]
  #the realSeparator is optional, only (aSeparator && aSeparator !== seperator
