diff --git a/src/intervals.c b/src/intervals.c
index 68728349e999c..6c3f36fec02aa 100644
--- a/src/intervals.c
+++ b/src/intervals.c
@@ -466,7 +466,7 @@ static int __set_delete(struct list_head *msgs, struct expr *i,	struct set *set,
 			unsigned int debug_mask)
 {
 	i->flags |= EXPR_F_REMOVE;
-	list_move(&i->list, &existing_set->init->expressions);
+	list_move_tail(&i->list, &existing_set->init->expressions);
 	list_expr_sort(&existing_set->init->expressions);
 
 	return setelem_delete(msgs, set, init, existing_set->init, debug_mask);
diff --git a/src/mergesort.c b/src/mergesort.c
index 4d0e280fdc5e2..5e676be16369b 100644
--- a/src/mergesort.c
+++ b/src/mergesort.c
@@ -78,7 +78,7 @@ void list_splice_sorted(struct list_head *list, struct list_head *head)
 	while (l != list) {
 		if (h == head ||
 		    expr_msort_cmp(list_entry(l, typeof(struct expr), list),
-				   list_entry(h, typeof(struct expr), list)) < 0) {
+				   list_entry(h, typeof(struct expr), list)) <= 0) {
 			l = l->next;
 			list_add_tail(l->prev, h);
 			continue;
diff --git a/tests/shell/testcases/sets/dumps/0055tcpflags_0.json-nft b/tests/shell/testcases/sets/dumps/0055tcpflags_0.json-nft
index 6a3511515f785..e37139f334466 100644
--- a/tests/shell/testcases/sets/dumps/0055tcpflags_0.json-nft
+++ b/tests/shell/testcases/sets/dumps/0055tcpflags_0.json-nft
@@ -28,15 +28,6 @@
           {
             "|": [
               "fin",
-              "psh",
-              "ack",
-              "urg"
-            ]
-          },
-          {
-            "|": [
-              "fin",
-              "psh",
               "ack"
             ]
           },
@@ -50,21 +41,22 @@
           {
             "|": [
               "fin",
+              "psh",
               "ack"
             ]
           },
           {
             "|": [
-              "syn",
+              "fin",
               "psh",
               "ack",
               "urg"
             ]
           },
+          "syn",
           {
             "|": [
               "syn",
-              "psh",
               "ack"
             ]
           },
@@ -78,22 +70,22 @@
           {
             "|": [
               "syn",
+              "psh",
               "ack"
             ]
           },
-          "syn",
           {
             "|": [
-              "rst",
+              "syn",
               "psh",
               "ack",
               "urg"
             ]
           },
+          "rst",
           {
             "|": [
               "rst",
-              "psh",
               "ack"
             ]
           },
@@ -107,12 +99,13 @@
           {
             "|": [
               "rst",
+              "psh",
               "ack"
             ]
           },
-          "rst",
           {
             "|": [
+              "rst",
               "psh",
               "ack",
               "urg"
@@ -126,11 +119,18 @@
           },
           {
             "|": [
+              "psh",
               "ack",
               "urg"
             ]
           },
-          "ack"
+          "ack",
+          {
+            "|": [
+              "ack",
+              "urg"
+            ]
+          }
         ]
       }
     }
diff --git a/tests/shell/testcases/sets/dumps/0055tcpflags_0.nft b/tests/shell/testcases/sets/dumps/0055tcpflags_0.nft
index ffed5426577e4..22bf5c461b877 100644
--- a/tests/shell/testcases/sets/dumps/0055tcpflags_0.nft
+++ b/tests/shell/testcases/sets/dumps/0055tcpflags_0.nft
@@ -2,9 +2,9 @@ table ip test {
 	set tcp_good_flags {
 		type tcp_flag
 		flags constant
-		elements = { fin | psh | ack | urg, fin | psh | ack, fin | ack | urg, fin | ack, syn | psh | ack | urg,
-			     syn | psh | ack, syn | ack | urg, syn | ack, syn, rst | psh | ack | urg,
-			     rst | psh | ack, rst | ack | urg, rst | ack, rst, psh | ack | urg,
-			     psh | ack, ack | urg, ack }
+		elements = { fin | ack, fin | ack | urg, fin | psh | ack, fin | psh | ack | urg, syn,
+			     syn | ack, syn | ack | urg, syn | psh | ack, syn | psh | ack | urg, rst,
+			     rst | ack, rst | ack | urg, rst | psh | ack, rst | psh | ack | urg, psh | ack,
+			     psh | ack | urg, ack, ack | urg }
 	}
 }
