anchor.diff:              end
       end.
   
  +build_zone(#zone{records = Records} = Zone) ->
  +    Zone#zone{authority = lists:filter(erldns_records:match_type(?DNS_TYPE_SOA), Records),
  +        records_by_name = build_named_index(Records)}.
  +
   build_zone(Qname, AllowNotifyList, AllowTransferList, AllowUpdateList, AlsoNotifyList,
              NotifySourceIP, Version, Records) ->
  -    RecordsByName = build_named_index(Records),
       Authority = lists:filter(erldns_records:match_type(?DNS_TYPE_SOA), Records),
       #zone{name = Qname, allow_notify = AllowNotifyList, allow_transfer = AllowTransferList,
             allow_update = AllowUpdateList, also_notify = AlsoNotifyList, notify_source = NotifySourceIP,
             version = Version, record_count = length(Records), authority = Authority, records = Records,
  -          records_by_name = RecordsByName}.
  +          records_by_name = build_named_index(Records)}.
   
   build_zone(Qname, AllowNotifyList, AllowTransferList, AllowUpdateList, AlsoNotifyList,
              NotifySourceIP, Version, Authority, Records) ->
  -    RecordsByName = build_named_index(Records),
       #zone{name = Qname, allow_notify = AllowNotifyList, allow_transfer = AllowTransferList,
             allow_update = AllowUpdateList, also_notify = AlsoNotifyList, notify_source = NotifySourceIP,
             version = Version, record_count = length(Records), authority = Authority, records = Records,
  -          records_by_name = RecordsByName}.
  +          records_by_name = build_named_index(Records)}.
   
   build_named_index(Records) -> build_named_index(Records, dict:new()).
   build_named_index([], Idx) -> Idx;
  -build_named_index([R|Rest], Idx) ->
  -    Expiry = timestamp() + R#dns_rr.ttl,
  -    case dict:find(R#dns_rr.name, Idx) of
  +build_named_index([#dns_rr{name = Name, ttl = TTL} = R |Rest], Idx) ->
  +    Expiry = timestamp() + TTL,
  +    case dict:find(Name, Idx) of
           {ok, Records} ->
  -            build_named_index(Rest, dict:store(normalize_name(R#dns_rr.name), Records ++ [{Expiry, R}], Idx));
  +            build_named_index(Rest, dict:store(normalize_name(Name), Records ++ [{Expiry, R}], Idx));
           error ->
  -            build_named_index(Rest, dict:store(normalize_name(R#dns_rr.name), [{Expiry, R}], Idx))
  +            build_named_index(Rest, dict:store(normalize_name(Name), [{Expiry, R}], Idx))
       end.
   
   normalize_name(Name) when is_list(Name) -> string:to_lower(Name);
  
positive.code: %% include in the SOA's mname field.
  %% @end
  -spec exclude_mname_duplicates(dns:rr(), [dns:rr()]) -> [dns:rr()].
  exclude_mname_duplicates(SOA, NameServers) ->
      MName = SOA#dns_rrdata_soa.mname,
      lists:foldl(fun(NameServer, Acc0) ->
                          case NameServer#dns_rrdata_ns.dname =:= MName of
                              true ->
                                  %% Found a NS record that is also a mname of an SOA, exclude it
                                  Acc0;
  
negative.code: get_notify_set([], SOA, NameServers) ->
      %% Remove mnames, and duplicates from final result
      exclude_mname_duplicates(SOA, NameServers);
  get_notify_set([#dns_rr{data = Data} | Tail], SOA, NameServers) ->
      case Data of
          #dns_rrdata_soa{}  = Authority ->
              get_notify_set(Tail, Authority, NameServers);
          #dns_rrdata_ns{} = NS ->
  