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


  if not sessionData.syncState?
    return callback()

  inception = sessionData.declarations.length - 1


    GET_PARAMETER_NAMES_DEPTH_THRESHOLD =
      config.get('GET_PARAMETER_NAMES_DEPTH_THRESHOLD', sessionData.deviceId)

    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)
      path = paths.pop()

    if path
      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
        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 =
