     GET_PARAMETER_NAMES_DEPTH_THRESHOLD =
       config.get('GET_PARAMETER_NAMES_DEPTH_THRESHOLD', sessionData.deviceId)
 
-    path = Array.from(syncState.gpn.keys()).sort((a,b) -> a.length - b.length)[0]
-    patterns = []
-    iter = sessionData.deviceData.paths.superset(path, 99)
-    while p = iter.next().value
-      if v = syncState.gpnPatterns.get(p)
-        patterns.push([p, (v >> path.length) << path.length])
-
-    if path.length >= GET_PARAMETER_NAMES_DEPTH_THRESHOLD
-      est = estimateGpnCount(patterns)
-    else
-      est = 0
-
-    if est < Math.pow(2, Math.max(0, 8 - path.length))
-      nextLevel = true
+    paths = Array.from(syncState.gpn.keys()).sort((a,b) -> b.length - a.length)
+    path = paths.pop()
+    while path and not sessionData.deviceData.attributes.has(path)
       syncState.gpn.delete(path)
-    else
-      nextLevel = false
-      iter = sessionData.deviceData.paths.subset(path, 99)
+      path = paths.pop()
+
+    if path
+      patterns = []
+      iter = sessionData.deviceData.paths.superset(path, 99)
       while p = iter.next().value
-        syncState.gpn.delete(p)
-
-    return {
-      type: 'GetParameterNames'
-      parameterPath: path.concat('').join('.')
-      nextLevel: nextLevel
-    }
+        if v = syncState.gpnPatterns.get(p)
+          patterns.push([p, (v >> path.length) << path.length])
+
+      if path.length >= GET_PARAMETER_NAMES_DEPTH_THRESHOLD
+        est = estimateGpnCount(patterns)
+      else
+        est = 0
+
+      if est < Math.pow(2, Math.max(0, 8 - path.length))
+        nextLevel = true
+        syncState.gpn.delete(path)
+      else
+        nextLevel = false
+        iter = sessionData.deviceData.paths.subset(path, 99)
+        while p = iter.next().value
+          syncState.gpn.delete(p)
+
+      return {
+        type: 'GetParameterNames'
+        parameterPath: path.concat('').join('.')
+        nextLevel: nextLevel
+      }
 
   if syncState.refreshAttributes.value.size
     TASK_PARAMETERS_BATCH_SIZE =

      else
        minInstances = maxInstances = declaration[3]

      parent = path.slice(0, -1)

      if Array.isArray(path[path.length - 1])
        keys = {}

  # Delete instance
  iter = syncState.instancesToDelete.values()
  while instances = iter.next().value
    if instance = instances.values().next().value and
        sessionData.deviceData.attributes.has(instance)
      return {
        type: 'DeleteObject'
        objectName: instance.concat('').join('.')
