 // =================================================================================
 void ISR_HANDLER_X()
 {
-  // Build the LUT index from previous and new data
-  xAxis.index       = (xAxis.index << 2) | ((PIND & 0b00000011) >> 0);
-  xAxis.coordinate += lookupTable[xAxis.index & 0b00001111];
+    // Build the LUT index from previous and new data
+    xAxis.index       = (xAxis.index << 2) | ((PIND & 0b00000011) >> 0);
+    xAxis.coordinate += lookupTable[xAxis.index & 0b00001111];
 }
 
 void ISR_HANDLER_Y()
 {
-  // Build the LUT index from previous and new data
-  yAxis.index       = (yAxis.index << 2) | ((PIND & 0b00001100) >> 2);
-  yAxis.coordinate += lookupTable[yAxis.index & 0b00001111];
+    // Build the LUT index from previous and new data
+    yAxis.index       = (yAxis.index << 2) | ((PIND & 0b00001100) >> 2);
+    yAxis.coordinate += lookupTable[yAxis.index & 0b00001111];
 }
 
 // =================================================================================

// =================================================================================
void loop()
{
  // Update mouse coordinates
  if (xAxis.coordinate != 0 || yAxis.coordinate != 0)
  {
    Mouse.move(xAxis.coordinate, yAxis.coordinate);
    xAxis.coordinate = 0;
    yAxis.coordinate = 0;
  }

  // ---------------------------------
  // Left mouse button state update
  // ---------------------------------
  ReadButton(leftButton);
  UpdateButton(leftButton);

  // ---------------------------------
  // Right mouse button state update
  // ---------------------------------  
  ReadButton(rightButton);
  UpdateButton(rightButton);
  
  // ---------------------------------
  // Middle mouse button state update
  // ---------------------------------
  ReadButton(middleButton);
  UpdateButton(middleButton);

  // Wait a little before next update
  delay(10);
}

// =================================================================================

// =================================================================================
void ReadButton(BUTTON_& button)
{
    // Variables
    long    currentime  = millis();
    boolean switchState = !(PINB & button.bitmask);
    boolean debounced   = (currentime - button.lastDebounceTime > DEBOUNCE_THREASHOLD);

    // Button state acquisition
    if ((switchState != button.state) && debounced)
    {
        button.lastDebounceTime = currentime;
        button.state            = switchState;
        button.needUpdate       = true;
    }
}

void UpdateButton(BUTTON_& button)
{
    if (button.needUpdate)
    {
        (button.state) ? Mouse.press(button.button) : Mouse.release(button.button);
        button.needUpdate = false;
    }
}
