 			}
 		}
 
-		// record the previous state
-		signals[i] = inRange(periodX, periodY);
-		i++;
-
-		if (i == sampleSize) {
+		if (i == sampleSize - 1) {
 			i = 0;
 		}
+    else {
+      i += 1;
+    }
 		delay(pollInterval);
 	}
 }

	// some variables used in this scope
	unsigned long startTime = 0;
	unsigned int periodX, periodY;
	unsigned int i, pulseCount, pollCounter = 0;
	int signals[] = { 0, 0, 0 };

	// Only here temporarily for debugging
	if (debug) {

		periodX = pulseIn(driverX, HIGH);
		periodY = pulseIn(driverY, HIGH);

    signals[i] = inRange(periodX, periodY);

		// Only here temporarily for debugging
		if (debug) {
			Serial.print("PeriodX: "); Serial.print(periodX); 
