     {
       // We have started calibrating!
       state = 1;
-      last_selector_pos = -1; // state 1 case will fix
+      // initialize photoresistor data.
+      for (int i=0; i<3; i++)
+      {
+        for (int j=0; j<7; j++)
+        {
+          photoresistor_totals[i][j] = 0;
+          photoresistor_counts[i][j] = 0;
+        }
+      }
     }
   }
 

}


// INPUT READING

// True if white gear is in front of photo resistor.  False if black paper.
// Undefined if gear not lodged.
boolean getPhotoresistor(int i) 
{
  // sees white gear
  if(analogRead(photoresistors[i]) > photoresistor_thresholds[i])
  {
    return true;
  }
  // sees black paper
  return false;
}

// based on the pot value, we know which of the 7 positions the selector gear is in

  // 0 in position 1.
  else if (positions_white == 4)
  {
    if (!photoresistor_history[0] && !photoresistor_history[3]
        && !photoresistor_history[6])
    {
      gear_types[i] = 0;
      gear_orientations[i] = 1;
