diff --git a/pixel.cpp b/pixel.cpp
index b7656246436d1a219efb7ddcada2a5211ef03e24..0026b3c3fcf37e54c60dabf3242fd301357b988d 100644
--- a/pixel.cpp
+++ b/pixel.cpp
@@ -25,13 +25,14 @@ void pixel(
 	pkt_t pkt=din.read();
 	count_streams++;
 
-	if(p_count==0){
-			count = 0;
-			flag=true;
-	}
+	
 	if(count == position || count == position+1 || count == position+2){
 		pkt.data -= 1;
 		p_count--;
+		if(p_count==0){
+			count = 0;
+			flag=true;
+	}
 
 	}
 	else if(!flag){