diff --git a/src/consumer.c b/src/consumer.c
index c5445f7874422a29fdf3c7390cc757a7da4a8820..e5d047ac7a95ffe46fe2efabb4cd03bd6a537524 100644
--- a/src/consumer.c
+++ b/src/consumer.c
@@ -16,7 +16,7 @@ void consumer_thread(void *args)
 	so_packet_t packet;
 	so_consumer_ctx_t *ctx = (so_consumer_ctx_t *)args;
 
-	while (1) {
+	while (true) {
 		pthread_mutex_lock(&ctx->producer_rb->mutex);
 
 		while (ctx->producer_rb->len == 0 && ctx->producer_rb->stop == 0)
@@ -34,7 +34,7 @@ void consumer_thread(void *args)
 			continue;
 
 		pthread_mutex_lock(&ctx->timestamp);
-		if (packet.hdr.timestamp >= (unsigned int)ctx->lasttimestamp) {
+		if (packet.hdr.timestamp >= ctx->lasttimestamp) {
 			ctx->lasttimestamp = packet.hdr.timestamp;
 
 			pthread_mutex_lock(&ctx->logs);
@@ -58,7 +58,7 @@ int create_consumers(pthread_t *tids,
 	FILE *f = fopen(out_filename, "a");
 
 	if (!f) {
-		perror("Failed to open output file");
+		printf("Failed to open output file\n");
 		return -1;
 	}
 
@@ -89,6 +89,7 @@ int create_consumers(pthread_t *tids,
 			for (int j = 0; j < i; j++)
 				pthread_join(tids[j], NULL);
 			pthread_mutex_destroy(&ctx->logs);
+			pthread_mutex_destroy(&ctx->timestamp);
 			free(ctx);
 			fclose(f);
 			return -1;
diff --git a/src/consumer.h b/src/consumer.h
index e4e61dbb142f07bb09d39ae1a3a53f1048335fa2..feb41333f48948c0035511b6ec0c88a32c0db2dd 100644
--- a/src/consumer.h
+++ b/src/consumer.h
@@ -15,7 +15,7 @@ typedef struct so_consumer_ctx_t {
 	FILE *f;
 	pthread_mutex_t logs;
 	pthread_mutex_t timestamp;
-	int lasttimestamp;
+	unsigned long lasttimestamp;
 } so_consumer_ctx_t;
 
 int create_consumers(pthread_t *tids,
diff --git a/src/ring_buffer.c b/src/ring_buffer.c
index 3440f1a587d2c5d24b1224301bf468f516c5ca26..2628a703732556f9a9a9545fed604023145fb141 100644
--- a/src/ring_buffer.c
+++ b/src/ring_buffer.c
@@ -50,6 +50,7 @@ ssize_t ring_buffer_enqueue(so_ring_buffer_t *ring, void *data, size_t size)
 		memcpy(ring->data + ring->write_pos, data, sizeleft);
 		memcpy(ring->data, (char *)data + sizeleft, size - sizeleft);
 	}
+
 	ring->write_pos = (ring->write_pos + size) % ring->cap;
 	ring->len = ring->len + size;