Fixed excessive querying when not needed for the ip address

Now it should work even with data not present in YAML.