     rudderInStart = micros();
   } else {
     rudderInValue = (uint16_t) (micros() - rudderInStart);
-    servoInputFlags |= FLAG_RUDDER;
+    receiverInputFlags |= FLAG_RUDDER;
   }
 }
 

        index++;
        if (index >= CHAR_ARRAY_SIZE) {
          index = CHAR_ARRAY_SIZE - 1;
          sendJson("error", "Serial buffer overflow");
        }
      }
      else {

  static uint16_t throttleInValueLocal;

  //If any servo input byte flags were set in any of the ISR methods, process them here
  if (receiverInputFlags != 0) {
    noInterrupts();
    //While interrupts are paused, copy new servo input values to the corresponding local static variables
    receiverInputFlagsLocal = receiverInputFlags;
    if (receiverInputFlagsLocal & FLAG_CUTOVER) cutoverInValueLocal = cutoverInValue;
      if (receiverControl || calibrationMode) {
        if (receiverInputFlagsLocal & FLAG_AILERON) aileronInValueLocal = aileronInValue;
        if (receiverInputFlagsLocal & FLAG_ELEVATOR) elevatorInValueLocal = elevatorInValue;
        if (receiverInputFlagsLocal & FLAG_RUDDER) rudderInValueLocal = rudderInValue;
        if (receiverInputFlagsLocal & FLAG_THROTTLE) throttleInValueLocal = throttleInValue;
      }
    receiverInputFlags = 0;
    interrupts();
  }
  //If the cutover switch is flipped, set receiverControl accordingly
  if (receiverInputFlagsLocal & FLAG_CUTOVER) {
    //Only use cutover values within the set range for receiver input
    if (calibrationMode && isValidReceiverInput(cutoverInValueLocal)) {
      if (cutoverInValueLocal > cutover.inputMax) cutover.inputMax = cutoverInValueLocal;
      if (cutoverInValueLocal < cutover.inputMin) cutover.inputMin = cutoverInValueLocal;
    } else if (isCalibrated) {
      //Calculate weighted average for cutover
      cutoverInputAverage = (cutoverInValueLocal + (CUTOVER_SAMPLE_SIZE - 1)*cutoverInputAverage)/CUTOVER_SAMPLE_SIZE;
      if (isValidReceiverInput(cutoverInputAverage)) {
        if (receiverControl && cutoverInputAverage > (cutover.inputMax - CUTOVER_MARGIN)) {
          receiverControl = false;
          //Checks if the cutover switched back and forth slower than the threshold (e.g. not emergency input stop)
          if ((millis() - receiverControlStartTime) > CUTOVER_THRESHOLD) {
            sharedControl = true;
            sendJsonBoolean("sharedControl", true);
          }
          sendJsonBoolean("receiverControl", receiverControl);
        } else if (!receiverControl && cutoverInputAverage < (cutover.inputMin + CUTOVER_MARGIN)) {
          sharedControl = false;
          receiverControl = true;
          sendJsonBoolean("receiverControl", receiverControl);
          sendJsonBoolean("sharedControl", false);
          receiverControlStartTime = millis();
        }
      } else if (receiverControl) {
        sendJsonString("error", "Cutover input out of range");
      }
    }
  }

  //Only process servo input if receiverControl or calibrationMode are enabled
  if (receiverControl || calibrationMode) {
    //Process input for each servo that received new input from the receiver
    if (receiverInputFlagsLocal & FLAG_AILERON) {
      processServoInput(aileron, aileronInValueLocal, "aileron", "Unassigned aileron pin", "Aileron input out of range");
    }
    if (receiverInputFlagsLocal & FLAG_ELEVATOR) {
      processServoInput(elevator, elevatorInValueLocal, "elevator", "Unassigned elevator pin", "Elevator input out of range");
    }
    if (receiverInputFlagsLocal & FLAG_RUDDER) {
      processServoInput(rudder, rudderInValueLocal, "rudder", "Unassigned rudder pin", "Rudder input out of range");
    }
    if (receiverInputFlagsLocal & FLAG_THROTTLE) {
      processServoInput(throttle, throttleInValueLocal, "throttle", "Unassigned throttle pin", "Throttle input out of range");
    }
  }
}

//Takes a key (text) value (boolean) pair and sends them as JSON over the serial interface
void sendJsonBoolean(const char key[], boolean value) {
  StaticJsonBuffer<CHAR_ARRAY_SIZE> jsonBuffer;
  JsonObject& root = jsonBuffer.createObject();
  root[key] = value;
