   Serial.println();
 }
 
-// ISR
-
 void timer_isr()
 {
   static int idx = -1;
-  idx = idx++ % BUF_LEN;
+  idx = ++idx % BUF_LEN;
 
-  ring_buffer[IRQ_0][idx] = pulse_count[IRQ_0];
-  ring_buffer[IRQ_1][idx] = pulse_count[IRQ_1];
+  for(int i =0;i < 2; i++)
+  {
+    ring_buffer[i][idx] = pulse_count[i];
+  }
 
   for(int i =0; i < 2; i++)
+  {
     pulse_count[i] = 0;
+  }
 }
 
 void tach_0_isr()

  pulse_count[IRQ_1]++;
}


  int counts[2][BUF_LEN];

  cli();

  tach_0 = pulse_count[0];
  tach_1 = pulse_count[1];

  for(int i = 0; i < 2; i++)
  {
    for(int j = 0; j < BUF_LEN; j++)
    {
      counts[i][j] = ring_buffer[i][j];
    }
  }

  sei();

  qsort(counts[IRQ_0], BUF_LEN, sizeof(int), cmp<int>);
  qsort(counts[IRQ_1], BUF_LEN, sizeof(int), cmp<int>);

  // report the median
  // send(counts[IRQ_0][BUF_LEN / 2], counts[IRQ_1][BUF_LEN / 2]);
  send(tach_0, tach_1);

  digitalWrite(LED, !digitalRead(LED));
  delay(1000 / HZ);
