Momentary midi sustain

I’ve searched around and still the answer is elusive. I have a simple code hooked up to a sustain pedal, interfacing to the laptop with a midi-usb cable.

What I want is to send 127 to CC66 when pedal is pushed, and 0 to CC66 when released (button state change). Basic sustain, stupid easy.
Attached code doesn’t work, it functions as a latching momentary. Why?

// pin to use for indicator LED
int ledPin = 12;
// pin that is connected to the footswitch
int buttonPin = 2;

int buttonState = 0;
int buttonLastState = 0;
int buttonInitState = 0;

int SusStatus = 0;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP);

  // Setup serial port for MIDI communication
  Serial.begin(31250);

  // read current button state, a press is detected whenever
  // state changes to anything else than the init state
  buttonInitState = digitalRead(buttonPin);
  // we only want to do something on state changes
  buttonLastState = buttonInitState;
}

void loop() {
  buttonState = digitalRead(buttonPin);

  // has the state changed?
  if (buttonState != buttonLastState) {
    buttonLastState = buttonState;
    if (buttonState != buttonInitState) {
      // button is in pressed state, trigger action
      if (SusStatus == 0) {
        // mute and light up LED
        digitalWrite(ledPin, HIGH);
        // send CC 66 on channel 2 with value 127 to sustain
        midiCc(1, 66, 127);
        SusStatus = 1;
      } else {
        // turn off LED and sustain
        digitalWrite(ledPin, LOW);
        midiCc(1, 66, 0);
        SusStatus = 0;
      }
    }
    // workaround to prevent fluttering of button state
    delay(10);
  }
}

void midiCc(int channel, int command, int value) {
  Serial.write(175 + channel);
  Serial.write(command);
  Serial.write(value);
}

Never mind I got it. I removed the susStatus from the loop, it was unnecessary and confusing it, and thought through the logic again. Here's what worked since there is always someone like me who will dig for answers:

void loop() {
  buttonState = digitalRead(buttonPin);

  // has the state changed?
   if (buttonState != buttonLastState) {
     buttonLastState = buttonState;
     if (buttonState != buttonInitState) {
        // button is pressed, send sustain
        // mute and light up LED
        digitalWrite(ledPin, HIGH);
        // send CC 66 on channel 2 with value 127 to sustain
        midiCc(1, 66, 127);
        } else {
        // button released turn off LED and sustain
        digitalWrite(ledPin, LOW);
        midiCc(1, 66, 0);
        }
    
    // workaround to prevent fluttering of button state
    delay(10);
   }
}