anchor.diff:  	  true -> 
   		  lager:debug("Processing RRSet (~p) for Zone (~p): counter (~p) provided is higher than system", [RRFqdn, ZoneName, Counter]),
   		  case find_zone_in_cache(erldns:normalize_name(ZoneName)) of
  -			{ok, Zone} -> Zone,
  +			{ok, Zone} ->
  +                          % lager:debug("DNSKEY RRSIGS at start of PUT (records: ~p)", [lists:filter(erldns_records:match_type_covered(?DNS_TYPE_DNSKEY_NUMBER), get_records_by_name_and_type(ZoneName, ?DNS_TYPE_RRSIG_NUMBER))]),
  +
   			  % TODO: remove debug
   			  lager:debug("Putting RRSet (~p) with Type: ~p for Zone (~p): ~p", [RRFqdn, Type, ZoneName, Records]),
   			  KeySets = Zone#zone.keysets,
  
positive.code: -spec(build_named_index([#dns_rr{}]) -> #{binary() => [#dns_rr{}]}).
  build_named_index(Records) ->
    NamedIndex = lists:foldl(fun (R, Idx) ->
      Name = erldns:normalize_name(R#dns_rr.name),
      maps:update_with(Name, fun (RR) -> [R | RR] end, [R], Idx)
    end, #{}, Records),
    maps:map(fun (_K, V) -> lists:reverse(V) end, NamedIndex).
  
  -spec(build_typed_index([#dns_rr{}]) -> #{dns:type() => [#dns_rr{}]}).
  build_typed_index(Records) ->
    TypedIndex = lists:foldl(fun (R, Idx) ->
      maps:update_with(R#dns_rr.type, fun (RR) -> [R | RR] end, [R], Idx)
    end, #{}, Records),
    maps:map(fun (_K, V) -> lists:reverse(V) end, TypedIndex).
  
  -spec(sign_zone(erldns:zone()) -> erldns:zone()).
  
negative.code:   erldns_storage:select_delete(zone_records_typed, [{{{erldns:normalize_name(Name), '_', '_'}, '_'},[],[true]}]).
  
  %% @doc Remove zone RRSet
  -spec delete_zone_rrset(binary(), binary(), binary(), integer(), integer()) -> any().
  delete_zone_rrset(ZoneName, Digest, RRFqdn, Type, Counter) ->
    case find_zone_in_cache(erldns:normalize_name(ZoneName)) of
      {ok, Zone} -> 
        Zone,
        CurrentCounter = get_rrset_sync_counter(ZoneName, RRFqdn, Type),
        case Counter of
          N when N =:= 0; CurrentCounter < N ->
            lager:debug("Removing RRSet (~p) with type ~p", [RRFqdn, Type]),
            % lager:debug("DNSKEY RRSIGS at start of DELETE (records: ~p)", [lists:filter(erldns_records:match_type_covered(?DNS_TYPE_DNSKEY_NUMBER), get_records_by_name_and_type(ZoneName, ?DNS_TYPE_RRSIG_NUMBER))]),
  
            erldns_storage:select_delete(zone_records, [{{{erldns:normalize_name(ZoneName), erldns:normalize_name(RRFqdn)}, '_'},[],[true]}]),
            erldns_storage:select_delete(zone_records_typed, [{{{erldns:normalize_name(ZoneName), erldns:normalize_name(RRFqdn), Type}, '_'},[],[true]}]),
  
            % remove the RRSIG for the given record type
            {_RRSigsCovering, RRSigsNotCovering} = lists:partition(erldns_records:match_type_covered(Type), get_records_by_name_and_type(ZoneName, ?DNS_TYPE_RRSIG_NUMBER)),
            % lager:debug("RRSIGs after partition (covering: ~p, notcovering: ~p)", [RRSigsCovering, RRSigsNotCovering]),
            erldns_storage:insert(zone_records_typed, {{erldns:normalize_name(ZoneName), erldns:normalize_name(RRFqdn), ?DNS_TYPE_RRSIG_NUMBER}, RRSigsNotCovering}),
  
            % only write counter if called explicitly with Counter value i.e. different than 0.
            % this will not write the counter if called by put_zone_rrset/3 as it will prevent subsequent delete ops
            case Counter of
              N when N > 0 ->
                % DELETE RRSet command has been sent - rebuild the zone_records named entry	
                rebuild_zone_records_named_entry(ZoneName, RRFqdn),
                % we need to update the zone digest as the zone content changes
                update_zone_records_and_digest(ZoneName, get_zone_records(ZoneName), Digest),
                write_rrset_sync_counter({ZoneName, RRFqdn, Type, Counter});
              _ ->
                ok
            end;
  
            % lager:debug("DNSKEY RRSIGS at end of DELETE (records: ~p)", [lists:filter(erldns_records:match_type_covered(?DNS_TYPE_DNSKEY_NUMBER), get_records_by_name_and_type(ZoneName, ?DNS_TYPE_RRSIG_NUMBER))]);
          N when CurrentCounter > N ->
            lager:debug("Not processing delete operation for RRSet (~p): counter (~p) provided is lower than system", [RRFqdn, Counter])
        end;
      _ -> {error, zone_not_found}
    end.
  
  %% @doc rebuild zone_records' entry using zone_records_typed
  -spec rebuild_zone_records_named_entry(binary(), binary()) -> any().
  