anchor.diff:  
   %% There were no exact matches on name, so move to the best-match resolution.
   resolve(Message, Qname, Qtype, _MatchedRecords = [], Host, CnameChain, Zone) ->
  -  %lager:debug("No exact matches, using best-match resolution"),
     best_match_resolution(Message, Qname, Qtype, Host, CnameChain, best_match(Qname, Zone), Zone);
   
   %% There was at least one exact match on name.
   resolve(Message, Qname, Qtype, MatchedRecords, Host, CnameChain, Zone) ->
  -  %lager:debug("Exect match on name ~p (records: ~p)", [Qname, MatchedRecords]),
     exact_match_resolution(Message, Qname, Qtype, Host, CnameChain, MatchedRecords, Zone).
   
   
  
positive.code:   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).
  
  
  
negative.code: 
  % Indicates CNAME loop
  resolve_best_match_with_wildcard_cname(Message, _Qname, _Qtype, _Host, _CnameChain, _BestMatchRecords, _Zone, _CnameRecords, true) ->
    Message#dns_message{aa = true, rc = ?DNS_RCODE_SERVFAIL};
  
  % We should follow the CNAME
  resolve_best_match_with_wildcard_cname(Message, _Qname, Qtype, Host, CnameChain, _BestMatchRecords, Zone, CnameRecords, false) ->
    CnameRecord = lists:last(CnameRecords),
    Name = CnameRecord#dns_rr.data#dns_rrdata_cname.dname,
    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)).
  