 
 void loop()
 {
+  HandleInputs();
+  
+  SetMotorState();
+    
+  UpdateClock();
+  UpdateDisplay();
+}
+
+void HandleInputs()
+{
   clockResetSwitch.update();
   if (clockResetSwitch.fell())
   {

    // doesn't work as well at low speed and we don't the bobbin to run ahead of
    // the flyer. So at the low end we start raising the delay toward max regardless
    // of what it's actually set to.
    delayBetweenAdjustments = map(absoluteCurrentSpeed, minimumSpeed, startOfStopDamping, maximumDelay, delayBetweenAdjustments);
  }

  if (currentSpeed == 0 && currentDirection != targetDirection)
  {
    // We're at zero speed and want to switch directions.   
    digitalWrite(directionOutPin, targetDirection);
    currentDirection = targetDirection;
    UpdateDirectionDisplay();
    
    // We don't want to actually start moving the other direction,
    // wait for the user to hit the power button again
    powerEnabled = false;
  }
  
  currentSpeed += SlewToward(currentSpeed, targetSpeed);
  analogWrite(speedOutPin, abs(currentSpeed));           
  
  UpdateClock();
  UpdateDisplay();
    
  // Rather than trying to write a fixed-delay loop we're being lazy and using a
  // variable-deplay loop to control the rate at which we change the motor speed.
  // This should be fine because we don't have anything urgent that we need to do
  // in between adjustments anyway and the input response lag even at maximum delay
  // will never be noticable to the user.
  delay(delayBetweenAdjustments);                     
}

boolean CanChangePowerState()

    targetSpeed = 0;
  }

  delayBetweenMotorUpdates = ReadPotentiometer(rateOfSpeedChangeInPin);
  delayBetweenMotorUpdates = map(delayBetweenMotorUpdates, 0, potentiometerCeiling, minimumDelay, maximumDelay);
  int absoluteCurrentSpeed = abs(currentSpeed);
  if (absoluteCurrentSpeed > abs(targetSpeed) && absoluteCurrentSpeed < startOfStopDamping)
  {
