anchor.diff:    case TypeMatches of
       [] ->
         %% Ask the custom handlers for their records.
  -      %lager:debug("Exact match for name, but no type matches in zone, try custom handlers"),
         NewRecords = lists:flatten(lists:map(custom_lookup(Qname, Qtype, MatchedRecords), erldns_handler:get_handlers())),
         resolve_exact_match(Message, Qname, Qtype, Host, CnameChain, MatchedRecords, Zone, NewRecords, AuthorityRecords);
       _ ->
  -      %lager:debug("Found exact match for name and type matches"),
         resolve_exact_match(Message, Qname, Qtype, Host, CnameChain, MatchedRecords, Zone, TypeMatches, AuthorityRecords)
     end.
   
   %% There were no matches for exact name and type, so now we are looking for NS records
   %% in the exact name matches.
   resolve_exact_match(Message, _Qname, Qtype, Host, CnameChain, MatchedRecords, Zone, _ExactTypeMatches = [], AuthorityRecords) ->
  -  %lager:debug("No exact matches for name and type"),
     ReferralRecords = lists:filter(erldns_records:match_type(?DNS_TYPE_NS), MatchedRecords), % Query matched records for NS type
     resolve_no_exact_type_match(Message, Qtype, Host, CnameChain, [], Zone, MatchedRecords, ReferralRecords, AuthorityRecords);
   
   %% There were exact matches of name and type.
   resolve_exact_match(Message, Qname, Qtype, Host, CnameChain, _MatchedRecords, Zone, ExactTypeMatches, AuthorityRecords) ->
  -  %lager:debug("Found exact matches of name and type. Authority records: ~p", [AuthorityRecords]),
     resolve_exact_type_match(Message, Qname, Qtype, Host, CnameChain, ExactTypeMatches, Zone, AuthorityRecords).
   
   
  
positive.code: 
  %% Indicates a CNAME loop. The response code is a SERVFAIL in this case.
  resolve_exact_match_with_cname(Message, _Qtype, _Host, _CnameChain, _MatchedRecords, _Zone, _CnameRecords, true) ->
    %lager:debug("CNAME loop detected (exact match)"),
    Message#dns_message{aa = true, rc = ?DNS_RCODE_SERVFAIL};
  % No CNAME loop, restart the query with the CNAME content.
  resolve_exact_match_with_cname(Message, Qtype, Host, CnameChain, _MatchedRecords, Zone, CnameRecords, false) ->
    CnameRecord = lists:last(CnameRecords),
    Name = CnameRecord#dns_rr.data#dns_rrdata_cname.dname,
    %lager:debug("Restarting query with CNAME name ~p (exact match)", [Name]),
    restart_query(Message#dns_message{aa = true, answers = Message#dns_message.answers ++ CnameRecords}, Name, Qtype, Host, CnameChain ++ CnameRecords, Zone, erldns_zone_cache:in_zone(Name)).
  
  
  
negative.code:   case TypeMatches of
      [] ->
        %% Ask the custom handlers for their records.
        NewRecords = lists:map(erldns_records:replace_name(Qname), lists:flatten(lists:map(custom_lookup(Qname, Qtype, MatchedRecords), erldns_handler:get_handlers()))),
        resolve_best_match_with_wildcard(Message, Qname, Qtype, Host, CnameChain, MatchedRecords, Zone, [], NewRecords);
      _ ->
        resolve_best_match_with_wildcard(Message, Qname, Qtype, Host, CnameChain, MatchedRecords, Zone, [], TypeMatches)
  