   motors.setLeftSpeed(-SPEED*adjust - 100);
 }
 
-// Converts x and y components of a vector to a heading in degrees
+// Converts x and y components of a vector to a heading in degrees.
+// This function is used instead of LSM303::heading() because we don't
+// want the acceleration of the Zumo to factor spuriously into the
+// tilt compensation that LSM303::heading() performs. This calculation
+// assumes that the Zumo is always level.
 int heading(LSM303::vector v)
 {
-  float xScaled =  2.0*(float)(v.x - compass.m_min.x) / ( compass.m_max.x - compass.m_min.x) - 1.0;
-  float yScaled =  2.0*(float)(v.y -  compass.m_min.y) / (compass.m_max.y - compass.m_min.y) - 1.0;
-
-  int angle = round(atan2(yScaled, xScaled)*180 / M_PI);
+  float x_scaled =  2.0*(float)(v.x - compass.m_min.x) / ( compass.m_max.x - compass.m_min.x) - 1.0;
+  float y_scaled =  2.0*(float)(v.y - compass.m_min.y) / (compass.m_max.y - compass.m_min.y) - 1.0;
+
+  int angle = round(atan2(y_scaled, x_scaled)*180 / M_PI);
   if (angle < 0)
     angle += 360;
   return angle;
 }
 
 // Yields the angle difference in degrees between two headings
-int relativeHeading(int headingFrom, int headingTo)
-{
-  if(headingFrom < headingTo)
-  {
-    return headingTo - headingFrom;
+int relativeHeading(int heading_from, int heading_to)
+{
+  if(heading_from < heading_to)
+  {
+    return heading_to - heading_from;
   }
   else
   {
-    return headingTo + (360 - headingFrom);
-  }
-}
-
-// We average 10 vectors to get a better measurement. The motors cause too much (magnetic) noise.
+    return heading_to + (360 - heading_from);
+  }
+}
+
+// Average 10 vectors to get a better measurement and help smooth out
+// the motors' magnetic interference.
 int averageHeading()
 {
   LSM303::vector avg = {0, 0, 0};

  avg.x /= 10.0;
  avg.y /= 10.0;

  // avg is the average measure of the north vector.
  return heading(avg);
}

    delay(1000);

    // Turn off motors and wait a short time to reduce interference from motors
    motors.setSpeeds(0, 0);
    delay(100);

    // Turn 90 degrees relative to the direction we are pointing.
    // This will help account for variable magnetic field, as opposed
    // to using fixed increments of 90 degrees from the initial
    // heading (which might have been measured in a different magnetic
    // field than the one the Zumo is experiencing now).
    target_heading = (averageHeading() + 90) % 360;
  }
  else
  {
    if((relative_heading - DEVIATION_RIGHT_THRESHOLD) < (DEVIATION_LEFT_THRESHOLD - relative_heading))
    {
      turnLeft(relative_heading - DEVIATION_RIGHT_THRESHOLD);
      Serial.print("     Turn Left");
    }
    else
    {
      turnRight(DEVIATION_LEFT_THRESHOLD - relative_heading);
      Serial.print("     Turn Right");
    }
  }
