  # Moved to the top of the function after rule::require_exists
  
  local peer_name
  peer_name=$(peers::find_by_ip "$client_ip")

  local subtype
  subtype=$(peers::get_meta "$peer_name" "subtype")

  local subnet
  subnet=$(config::subnet_for "$subtype")

  # Changed this part from -n to -z
  # Remove DNS redirect if applicable
  local dns_redirect
  dns_redirect=$(rule::get "$rule_name" "dns_redirect")
  if [[ "$dns_redirect" == "true" ]]; then
    if [[ -z "$subtype" ]]; then
      local peer_type
      peer_type=$(peers::get_type "$peer_name") || true
      [[ -z "$peer_type" ]] && peer_type="phone"  # fallback
      subnet=$(config::subnet_for "$peer_type")
    fi

    rule::remove_dns_redirect "${subnet}.0/24"
  fi