anchor.diff:        end
     end.
   
  -
  +%% We are authoritative and there were no NS records here.
   resolve_exact_type_match(Message, _Qname, _Qtype, _Host, _CnameChain, MatchedRecords, _Zone, _AuthorityRecords, []) ->
  -  %lager:debug("Returning authoritative answer with ~p appended answers", [length(MatchedRecords)]),
     Message#dns_message{aa = true, rc = ?DNS_RCODE_NOERROR, answers = Message#dns_message.answers ++ MatchedRecords};
   
  +%% We are authoritative and there are NS records here.
   resolve_exact_type_match(Message, _Qname, Qtype, Host, CnameChain, MatchedRecords, Zone, _AuthorityRecords, NSRecords) ->
     Answer = lists:last(MatchedRecords),
     NSRecord = lists:last(NSRecords),
     Name = NSRecord#dns_rr.name,
  -  %lager:debug("Name: ~p; answer name: ~p", [Name, Answer#dns_rr.name]),
     case Name =:= Answer#dns_rr.name of
       true ->
  -      %lager:debug("Name matches an existing answer name so this is an authority"),
         Message#dns_message{aa = false, rc = ?DNS_RCODE_NOERROR, authority = Message#dns_message.authority ++ NSRecords};
       false ->
  -      %lager:debug("Restarting query with delegated name ~p", [Name]),
         restart_delegated_query(Message, Name, Qtype, Host, CnameChain, Zone, erldns_zone_cache:in_zone(Name))
     end.
   
  
positive.code:   % It isn't clear what the QTYPE should be on a delegated restart. I assume an A record.
    restart_delegated_query(Message, Name, ?DNS_TYPE_A, Host, CnameChain, Zone, erldns_zone_cache:in_zone(Name));
  
  resolve_exact_type_match(Message, _Qname, ?DNS_TYPE_NS, _Host, _CnameChain, MatchedRecords, _Zone, _AuthorityRecords) ->
    %lager:debug("Authoritative for record, returning answers"),
    Message#dns_message{aa = true, rc = ?DNS_RCODE_NOERROR, answers = Message#dns_message.answers ++ MatchedRecords};
  
  resolve_exact_type_match(Message, Qname, Qtype, Host, CnameChain, MatchedRecords, Zone, _AuthorityRecords) ->
    Answer = lists:last(MatchedRecords),
    SoaRecordResult = erldns_zone_cache:get_authority(Qname),
    case NSRecords = erldns_zone_cache:get_delegations(Answer#dns_rr.name) of
  
negative.code:   resolve_best_match_referral(Message, Qname, Qtype, Host, CnameChain, BestMatchRecords, Zone, ReferralRecords).
  
  
  % There is no referral, so check to see if there is a wildcard.
  resolve_best_match(Message, Qname, Qtype, Host, CnameChain, BestMatchRecords, Zone) ->
    %lager:debug("No referrals found"),
    resolve_best_match(Message, Qname, Qtype, Host, CnameChain, BestMatchRecords, Zone, lists:any(erldns_records:match_wildcard(), BestMatchRecords)).
  