diff --git a/src/libknot/rrset.c b/src/libknot/rrset.c
index c1570d1bd7b58d8fd0c326d9096242141fc7c71e..29cb916e4f19ef6b5baa1025b74d8603ede804c6 100644
--- a/src/libknot/rrset.c
+++ b/src/libknot/rrset.c
@@ -78,7 +78,7 @@ void knot_rrset_rdata_dump(const knot_rrset_t *rrset, size_t rdata_pos)
 				fprintf(stderr, "DNAME error.\n");
 				return;
 			}
-			fprintf(stderr, "block=%d: (%p) DNAME=%s.\n",
+			fprintf(stderr, "block=%d: (%p) DNAME=%s\n",
 			        i, dname, name);
 			free(name);
 			offset += sizeof(knot_dname_t *);
@@ -590,14 +590,19 @@ static int knot_rrset_rdata_to_wire_one(const knot_rrset_t *rrset,
 	size_t size = header_size;
 	
 	for (int i = 0; desc->block_types[i] != KNOT_RDATA_WF_END; i++) {
-		if (descriptor_item_is_dname(desc->block_types[i])) {
-			knot_dname_t *dname = 
-				(knot_dname_t *)(rdata + offset);
+		int item = desc->block_types[i];
+		if (descriptor_item_is_dname(item)) {
+			knot_dname_t *dname;
+			memcpy(&dname, rdata + offset, sizeof(knot_dname_t *));
 			assert(dname);
 			if (size + *rdlength + dname->size > max_size) {
 				return KNOT_ESPACE;
 			}
-
+dbg_rrset_exec_detail(
+			char *name = knot_dname_to_str(dname);
+			dbg_rrset_detail("Saving this DNAME=%s\n", name);
+			free(name);
+);
 			// save whole domain name
 			memcpy(*pos, knot_dname_name(dname), 
 			       knot_dname_size(dname));
@@ -606,17 +611,16 @@ static int knot_rrset_rdata_to_wire_one(const knot_rrset_t *rrset,
 			*pos += knot_dname_size(dname);
 			*rdlength += knot_dname_size(dname);
 			offset += sizeof(knot_dname_t *);
-		} else if (descriptor_item_is_fixed(desc->block_types[i])) {
+		} else if (descriptor_item_is_fixed(item)) {
 			/* Fixed length chunk. */
-			if (size + *rdlength + desc->block_types[i] > max_size) {
+			if (size + *rdlength + item > max_size) {
 				return KNOT_ESPACE;
 			}
-			memcpy(*pos, rdata + offset,
-			       desc->block_types[i]);
-			*pos += desc->block_types[i];
-			*rdlength += desc->block_types[i];
-			offset += desc->block_types[i];
-		} else if (descriptor_item_is_remainder(desc->block_types[i])) {
+			memcpy(*pos, rdata + offset, item);
+			*pos += item;
+			*rdlength += item;
+			offset += item;
+		} else if (descriptor_item_is_remainder(item)) {
 			/* Check that the remainder fits to stream. */
 			size_t remainder_size =
 				rrset_rdata_remainder_size(rrset, offset,
diff --git a/src/tests/libknot/libknot/rrset_tests.c b/src/tests/libknot/libknot/rrset_tests.c
index 6511b1fc4eda67214d518bbd97c6f99abdf1f81c..0e7bbb67977bf61f2f7998881a8f2b479db86911 100644
--- a/src/tests/libknot/libknot/rrset_tests.c
+++ b/src/tests/libknot/libknot/rrset_tests.c
@@ -123,7 +123,7 @@ static test_rdata_t test_rdata_array[TEST_RDATA_COUNT] = {
 	[TEST_RDATA_MX_DNAME_LESS] = {NULL, NULL, sizeof(knot_dname_t *) + 2, 0},
 	[TEST_RDATA_MX_DNAME_GT] = {NULL, NULL, sizeof(knot_dname_t *) + 2, 0},
 	[TEST_RDATA_MX_BIN_LESS] = {NULL, NULL, sizeof(knot_dname_t *) + 2, 0},
-	[TEST_RDATA_MX_BIN_GT] = {NULL, NULL, sizeof(knot_dname_t *) + 2, 0},
+	[	TEST_RDATA_MX_BIN_GT] = {NULL, NULL, sizeof(knot_dname_t *) + 2, 0},
 	[TEST_RDATA_MINFO1] = {NULL, NULL, sizeof(knot_dname_t *) * 2, 0},
 	[TEST_RDATA_MINFO2] = {NULL, NULL, sizeof(knot_dname_t *) * 2, 0}
 };
@@ -319,8 +319,9 @@ static void create_test_rrsets()
 		/* Assign owner. */
 		test_rrset->rrset.owner = test_dnames[test_rrset->owner_id];
 		/* Create header wire. */
+		test_rrset->header_wire_size = test_rrset->rrset.owner->size + 8 + 2;
 		test_rrset->header_wire =
-			xmalloc(test_rrset->rrset.owner->size + 8 + 2);
+			xmalloc(test_rrset->header_wire_size);
 		/* Copy owner wire to header wire. */
 		memcpy(test_rrset->header_wire, test_rrset->rrset.owner->name,
 		       test_rrset->rrset.owner->size);
@@ -354,6 +355,7 @@ static void create_test_rrsets()
 		offset = 0;
 		test_rrset->rrset.rdata = xmalloc(actual_length);
 		test_rrset->rdata_wire = xmalloc(rdlength);
+		test_rrset->rdata_wire_size = rdlength;
 		test_rrset->rrset.rdata_indices =
 			xmalloc(sizeof(uint32_t) * test_rrset->rr_count);
 		for (int j = 0; j < test_rrset->rr_count; j++) {
@@ -378,7 +380,7 @@ static void create_test_rrsets()
 			       test_rrset->test_rdata[j]->wire_size);
 			offset += test_rrset->test_rdata[j]->wire_size;
 		}
-		test_rrset->rdata_wire_size = offset;
+		assert(offset == rdlength);
 	}
 }
 
@@ -675,6 +677,7 @@ static int test_rrset_to_wire()
 	uint16_t rr_count = 0;
 	int failed = 0;
 	for (int i = 0; i < TEST_RRSET_COUNT; i++) {
+		memset(wire, 0, wire_size);
 		wire_size = 65535;
 		/* Convert to wire. */
 		int ret = knot_rrset_to_wire(&test_rrset_array[i].rrset, wire,
@@ -693,6 +696,16 @@ static int test_rrset_to_wire()
 			return 0;
 		}
 		
+		if (wire_size != test_rrset_array[i].rdata_wire_size +
+		    test_rrset_array[i].header_wire_size) {
+			diag("Wrong wire size, in RRSet=%d "
+			     "(should be=%d, is=%d).\n", i,
+			     test_rrset_array[i].rdata_wire_size +
+			     test_rrset_array[i].header_wire_size, wire_size);
+			failed = 1;
+			continue;
+		}
+		
 		/* Check that the RDATA are OK. */
 		ret = memcmp(wire + test_rrset_array[i].header_wire_size,
 		             test_rrset_array[i].rdata_wire,
@@ -701,6 +714,10 @@ static int test_rrset_to_wire()
 			diag("RDATA of RRSet %d are wrongly converted.\n",
 			     i);
 			failed = 1;
+			hex_print(wire + test_rrset_array[i].header_wire_size,
+			          test_rrset_array[i].rdata_wire_size);
+			hex_print(test_rrset_array[i].rdata_wire,
+			          test_rrset_array[i].rdata_wire_size);
 		}
 	}