relocate counterchanges
diff --git a/communication.c b/communication.c
index c245514..d0f4139 100644
--- a/communication.c
+++ b/communication.c
@@ -296,12 +296,13 @@
 
 // gets executed after deliver_table
 void
-deliver_counters(struct ebt_u_replace *u_repl, unsigned short *counterchanges)
+deliver_counters(struct ebt_u_replace *u_repl)
 {
 	unsigned short *point;
 	struct ebt_counter *old, *new, *newcounters;
 	socklen_t optlen;
 	struct ebt_replace repl;
+	unsigned short *counterchanges = u_repl->counterchanges;
 
 	if (u_repl->nentries == 0)
 		return;
diff --git a/ebtables.c b/ebtables.c
index 56fd630..a8d2202 100644
--- a/ebtables.c
+++ b/ebtables.c
@@ -123,8 +123,6 @@
 unsigned char mac_type_broadcast[ETH_ALEN] = {255,255,255,255,255,255};
 unsigned char msk_type_broadcast[ETH_ALEN] = {255,255,255,255,255,255};
 
-// tells what happened to the old rules
-static unsigned short *counterchanges;
 // holds all the data
 static struct ebt_u_replace replace;
 
@@ -900,16 +898,16 @@
 		replace.num_counters = replace.nentries;
 		if (replace.nentries) {
 			// '+ 1' for the CNT_END
-			if (!(counterchanges = (unsigned short *) malloc(
+			if (!(replace.counterchanges = (unsigned short *) malloc(
 			   (replace.nentries + 1) * sizeof(unsigned short))))
 				print_memory();
 			// done nothing special to the rules
 			for (i = 0; i < replace.nentries; i++)
-				counterchanges[i] = CNT_NORM;
-			counterchanges[replace.nentries] = CNT_END;
+				replace.counterchanges[i] = CNT_NORM;
+			replace.counterchanges[replace.nentries] = CNT_END;
 		}
 		else
-			counterchanges = NULL;
+			replace.counterchanges = NULL;
 	}
 	else
 		exit(0);
@@ -966,14 +964,14 @@
 
 	if (replace.nentries) {
 		// +1 for CNT_END
-		if ( !(counterchanges = (unsigned short *)
+		if ( !(replace.counterchanges = (unsigned short *)
 		   malloc((oldnentries + 1) * sizeof(unsigned short))) )
 			print_memory();
 	}
 	// delete the counters belonging to the specified chain,
 	// update counter_offset
 	i = -1;
-	cnt = counterchanges;
+	cnt = replace.counterchanges;
 	while (1) {
 		i++;
 		entries = nr_to_chain(i);
@@ -1136,10 +1134,10 @@
 
 	// handle counter stuff
 	// +1 for CNT_END
-	if ( !(counterchanges = (unsigned short *)
+	if ( !(replace.counterchanges = (unsigned short *)
 	   malloc((replace.nentries + 1) * sizeof(unsigned short))) )
 		print_memory();
-	cnt = counterchanges;
+	cnt = replace.counterchanges;
 	for (i = 0; i < replace.selected_hook; i++) {
 		if (i < NF_BR_NUMHOOKS && !(replace.valid_hooks & (1 << i)))
 			continue;
@@ -1155,7 +1153,7 @@
 	}
 	*cnt = CNT_ADD;
 	cnt++;
-	while (cnt != counterchanges + replace.nentries) {
+	while (cnt != replace.counterchanges + replace.nentries) {
 		*cnt = CNT_NORM;
 		cnt++;
 	}
@@ -1228,10 +1226,10 @@
 		}
 		lentmp += i;
 		// +1 for CNT_END
-		if ( !(counterchanges = (unsigned short *)malloc(
+		if ( !(replace.counterchanges = (unsigned short *)malloc(
 		   (replace.num_counters + 1) * sizeof(unsigned short))) )
 			print_memory();
-		cnt = counterchanges;
+		cnt = replace.counterchanges;
 		for (j = 0; j < lentmp; j++) {
 			*cnt = CNT_NORM;
 			cnt++;
@@ -1288,7 +1286,7 @@
 		// tell main() we don't update the counters
 		// this results in tricking the kernel to zero its counters,
 		// naively expecting userspace to update its counters. Muahahaha
-		counterchanges = NULL;
+		replace.counterchanges = NULL;
 		replace.num_counters = 0;
 	} else {
 		int i, j;
@@ -1297,11 +1295,11 @@
 
 		if (entries->nentries == 0)
 			exit(0);
-		counterchanges = (unsigned short *)
+		replace.counterchanges = (unsigned short *)
 		   malloc((replace.nentries + 1) * sizeof(unsigned short));
-		if (!counterchanges)
+		if (!replace.counterchanges)
 			print_memory();
-		cnt = counterchanges;
+		cnt = replace.counterchanges;
 		for (i = 0; i < zerochain; i++) {
 			if (i < NF_BR_NUMHOOKS &&
 			   !(replace.valid_hooks & (1 << i)))
@@ -1316,7 +1314,7 @@
 			*cnt = CNT_ZERO;
 			cnt++;
 		}
-		while (cnt != counterchanges + replace.nentries) {
+		while (cnt != replace.counterchanges + replace.nentries) {
 			*cnt = CNT_NORM;
 			cnt++;
 		}
@@ -1563,6 +1561,7 @@
 	replace.selected_hook = -1;
 	replace.command = 'h';
 	replace.filename = NULL;
+	replace.counterchanges = NULL;
 
 	new_entry = (struct ebt_u_entry *)malloc(sizeof(struct ebt_u_entry));
 	if (!new_entry)
@@ -2051,11 +2050,11 @@
 			// get the information from the file
 			get_table(&replace);
                         if (replace.nentries) {
-                                counterchanges = (unsigned short *)
+                                replace.counterchanges = (unsigned short *)
                                    malloc(sizeof(unsigned short) * (replace.nentries + 1));
 				for (i = 0; i < replace.nentries; i++)
-                                        counterchanges[i] = CNT_NORM;
-                                counterchanges[i] = CNT_END;
+					replace.counterchanges[i] = CNT_NORM;
+					replace.counterchanges[i] = CNT_END;
                         }
 			free(replace.filename);
 			replace.filename = NULL;
@@ -2076,11 +2075,11 @@
 					"table %s", replace.name);
 			}
 			if (replace.nentries) {
-				counterchanges = (unsigned short *)
+				replace.counterchanges = (unsigned short *)
 				   malloc(sizeof(unsigned short) * (replace.nentries + 1));
 				for (i = 0; i < replace.nentries; i++)
-					counterchanges[i] = CNT_NORM;
-				counterchanges[i] = CNT_END;
+					replace.counterchanges[i] = CNT_NORM;
+				replace.counterchanges[i] = CNT_END;
 			}
 			if (c == 11)
 				break;
@@ -2225,7 +2224,7 @@
 
 	deliver_table(&replace);
 
-	if (counterchanges)
-		deliver_counters(&replace, counterchanges);
+	if (replace.counterchanges)
+		deliver_counters(&replace);
 	return 0;
 }
diff --git a/include/ebtables_u.h b/include/ebtables_u.h
index 7eff5b2..de67a8d 100644
--- a/include/ebtables_u.h
+++ b/include/ebtables_u.h
@@ -68,6 +68,8 @@
 	int selected_hook;
 	// used for the atomic option
 	char *filename;
+	// tells what happened to the old rules
+	unsigned short *counterchanges;
 };
 
 struct ebt_u_table
@@ -194,8 +196,7 @@
 struct ebt_u_match *find_match(const char *name);
 struct ebt_u_watcher *find_watcher(const char *name);
 struct ebt_u_table *find_table(char *name);
-void deliver_counters(struct ebt_u_replace *repl,
-   unsigned short * counterchanges);
+void deliver_counters(struct ebt_u_replace *repl);
 void deliver_table(struct ebt_u_replace *repl);
 void get_dbinfo(struct brdb_dbinfo *nr);
 void get_db(int len, struct brdb_dbentry *db);