Midi filtertering of stop start messages

Deva_Rishi, in case your still watching this I'd like to pick your brains on another issue using similar code. Except, this time I'm not filtering out stop and start messages as I need them. Once again I'm using a master clock to control my Uno. From my Uno I have a keyboard plugged in which responds to stop and start as well as tempo change without issue. However, each time I stop and start the master clock the LED on the Uno doesn't really sync with the master clock's LED but the keyboard does perfectly. How might I modify the code to have the Uno's LED sync with the master clock after every stop and start?


// MIDI clock as per Little Scale
byte midi_start = 0xfa;
byte midi_stop = 0xfc;
byte midi_clock = 0xf8;
byte midi_continue = 0xfb;

static uint8_t clk = 0;


// Variables
int tempoled = 13;
int play_flag = 0;
byte data;


// Setup
void setup() {
  Serial.begin(31250);
  pinMode(tempoled, OUTPUT);
}


// Program
void loop() {

  if (Serial.available() > 0) {
    data = Serial.read();

    if (data == midi_start) { // if midi in start
      Serial.write(midi_start); // send midi out start

      play_flag = 1;
    }

    if (data == midi_continue) { // if midi in continue
      Serial.write(midi_continue); // send midi out continue

      play_flag = 1;
    }

    if (data == midi_stop) { // if midi in stop
      Serial.write(midi_stop); // send midi out stop
      play_flag = 0;
    }



    else if ((data == midi_clock) && (play_flag == 1)) {
      clk++;
      clk = clk % 24;                                 // 24 clock messages per beat
      if (clk / 6) digitalWrite(tempoled, LOW);  // this should light it up for 25% of the time
      else digitalWrite(tempoled, HIGH);
      Serial.write(midi_clock); // send midi clock to out... Provides tempo!

    }
  }
}