docs: def merge_config(d1, d2):
      '''Merges to config dicts. Key values are case insensitive for merging,
      but the value of d1 is remembered.
      '''
      result = deepcopy(d1)
      elements = deque()
      elements.append((result, d2))
  
      while elements:
          old, new = elements.popleft()
  
          new = OrderedDict([(k.lower(), (k, v)) for k, v in new.items()])
          visited_keys = []
  
          for k, old_value in old.items():
              klow = k.lower()
              if klow in new:
                  new_key, new_value = new[klow]
                  visited_keys.append(new_key)
                  if all(isinstance(e, MutableMapping) for e in (old_value, new_value)):
                      elements.append((old_value, new_value))
                  else:
                      old[k] = deepcopy(new_value)
  
          for k, v in new.values():
              if k not in visited_keys:
                  old[k] = deepcopy(v)
  
      return result