diff --git a/lib/layer/rrcache.c b/lib/layer/rrcache.c
index 4c9598f2256eec962f2c7560842addedc7bf7e2a..0db816f0e9fcb5454def87b5204fb05235a4892a 100644
--- a/lib/layer/rrcache.c
+++ b/lib/layer/rrcache.c
@@ -203,7 +203,7 @@ static void stash_glue(map_t *stash, knot_pkt_t *pkt, const knot_dname_t *ns_nam
 		    !knot_dname_is_equal(rr->owner, ns_name)) {
 			continue;
 		}
-		kr_rrmap_add(stash, rr, pool);
+		kr_rrmap_add(stash, rr, KR_RANK_BAD, pool);
 	}
 }
 
@@ -214,7 +214,7 @@ static void stash_ds(struct kr_query *qry, knot_pkt_t *pkt, map_t *stash, mm_ctx
 	for (unsigned i = 0; i < authority->count; ++i) {
 		const knot_rrset_t *rr = knot_pkt_rr(authority, i);
 		if (rr->type == KNOT_RRTYPE_DS || rr->type == KNOT_RRTYPE_RRSIG) {
-			kr_rrmap_add(stash, rr, pool);
+			kr_rrmap_add(stash, rr, KR_RANK_AUTH, pool);
 		}
 	}
 }
@@ -233,7 +233,7 @@ static int stash_authority(struct kr_query *qry, knot_pkt_t *pkt, map_t *stash,
 			stash_glue(stash, pkt, knot_ns_name(&rr->rrs, 0), pool);
 		}
 		/* Stash record */
-		kr_rrmap_add(stash, rr, pool);
+		kr_rrmap_add(stash, rr, KR_RANK_NONAUTH, pool);
 	}
 	return kr_ok();
 }
@@ -250,7 +250,7 @@ static int stash_answer(struct kr_query *qry, knot_pkt_t *pkt, map_t *stash, mm_
 		    && rr->type != KNOT_RRTYPE_RRSIG) {
 			continue;
 		}
-		kr_rrmap_add(stash, rr, pool);
+		kr_rrmap_add(stash, rr, KR_RANK_AUTH, pool);
 		/* Follow CNAME chain in current cut. */
 		if (rr->type == KNOT_RRTYPE_CNAME) {
 			const knot_dname_t *next_cname = knot_cname_name(&rr->rrs);
diff --git a/lib/layer/validate.c b/lib/layer/validate.c
index 68d2943a9717b1793ac655c923e136d301487d87..bd96b381be16454475fc29ecab06893a3523dba3 100644
--- a/lib/layer/validate.c
+++ b/lib/layer/validate.c
@@ -91,7 +91,7 @@ static int validate_section(struct kr_query *qry, knot_pkt_t *answer,
 		if (section_id == KNOT_ANSWER && !knot_dname_in(qry->zone_cut.name, rr->owner)) {
 			continue;
 		}
-		ret = kr_rrmap_add(&stash, rr, pool);
+		ret = kr_rrmap_add(&stash, rr, 0, pool);
 		if (ret != 0) {
 			goto fail;
 		}
diff --git a/lib/utils.c b/lib/utils.c
index a5295ceb4a9f81fd8b222b13313304b075a2e954..02ae24605e46e545e3aaaf8feff3ef9ab8878293 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -264,10 +264,7 @@ int kr_bitcmp(const char *a, const char *b, int bits)
 	return ret;
 }
 
-/* Set stashed RR flag */
-#define KEY_FLAG_SET(key, flag) key[0] = (flag);
-
-int kr_rrmap_add(map_t *stash, const knot_rrset_t *rr, mm_ctx_t *pool)
+int kr_rrmap_add(map_t *stash, const knot_rrset_t *rr, uint8_t rank, mm_ctx_t *pool)
 {
 	if (!stash || !rr) {
 		return kr_error(EINVAL);
@@ -276,13 +273,13 @@ int kr_rrmap_add(map_t *stash, const knot_rrset_t *rr, mm_ctx_t *pool)
 	/* Stash key = {[1] flags, [1-255] owner, [1-5] type, [1] \x00 } */
 	char key[9 + KNOT_DNAME_MAXLEN];
 	uint16_t rrtype = rr->type;
-	KEY_FLAG_SET(key, KEY_FLAG_NO);
+	key[0] = (rank << 2) | 0x01; /* Must be non-zero */
 
 	/* Stash RRSIGs in a special cache, flag them and set type to its covering RR.
 	 * This way it the stash won't merge RRSIGs together. */
 	if (rr->type == KNOT_RRTYPE_RRSIG) {
 		rrtype = knot_rrsig_type_covered(&rr->rrs, 0);
-		KEY_FLAG_SET(key, KEY_FLAG_RRSIG);
+		key[0] |= KEY_FLAG_RRSIG;
 	}
 
 	uint8_t *key_buf = (uint8_t *)key + 1;
diff --git a/lib/utils.h b/lib/utils.h
index a73d162319d38c558a12dccbe105b3467132582b..a63165f9b6b5b79daf53bdf867a7e04bf1838c4d 100644
--- a/lib/utils.h
+++ b/lib/utils.h
@@ -113,12 +113,12 @@ int kr_straddr_subnet(void *dst, const char *addr);
 int kr_bitcmp(const char *a, const char *b, int bits);
 
 /** @internal RR map flags. */
-#define KEY_FLAG_NO 0x01
 #define KEY_FLAG_RRSIG 0x02
+#define KEY_FLAG_RANK(key) (key[0] >> 2)
 #define KEY_COVERING_RRSIG(key) (key[0] & KEY_FLAG_RRSIG)
 
 /** @internal Merges RRSets with matching owner name and type together.
  * @note RRSIG RRSets are merged according the type covered fields.
  * @return 0 or an error
  */
-int kr_rrmap_add(map_t *stash, const knot_rrset_t *rr, mm_ctx_t *pool);
\ No newline at end of file
+int kr_rrmap_add(map_t *stash, const knot_rrset_t *rr, uint8_t rank, mm_ctx_t *pool);
\ No newline at end of file