   path = path.slice(0, trimWildcard) if trimWildcard < path.length
 
   for i in [0..path.length] by 1
-    for sup in sessionContext.deviceData.paths.find(path.slice(0, i), true, false)
-      v = sessionContext.deviceData.loaded.get(sup)
-      depth &= depth ^ sessionContext.deviceData.loaded.get(sup)
-
-    return true if depth == 0
-
-  sessionContext.toLoad ?= []
-  sessionContext.toLoad.push([path, depth])
+    d = if i == path.length then 99 else i
+    for sup in sessionContext.deviceData.paths.find(path.slice(0, i), true, false, d)
+      v = sessionContext.deviceData.loaded.get(sup) | sessionContext.toLoad.get(sup)
+      if sup.length > i
+        v &= (1 << i) - 1
+      depth &= depth ^ v
+      return true if depth == 0
+
+  path = sessionContext.deviceData.paths.add(path)
+  depth |= sessionContext.toLoad.get(path)
+  sessionContext.toLoad.set(path, depth)
   return false
 
 



loadParameters = (sessionContext, callback) ->
  if not sessionContext.toLoad?.length
    return callback()

  db.fetchDevice(sessionContext.deviceId, sessionContext.timestamp, sessionContext.toLoad, (err, parameters, loaded) ->
    return callback(err) if err

    if not parameters?



loadPath = (sessionContext, path, depth) ->
  depth = depth or (1 << path.length) - 1
  return true if sessionContext.new or not depth

  sessionContext.toLoad ?= new Map()

  # Trim trailing wildcards
  trimWildcard = path.length
