Help with code for Midi legato playing and pitchbend

i added a line in the code and its working properly now i think, is there any other way of implementing this in your code?

void MyHandleNoteOn(byte channel, byte pitch, byte velocity) { 
  
  if(pitch == 62)
    note62playing = true;
  else
    otherNotesPlaying++;
  if (note62playing && otherNotesPlaying == 0)
    MIDI.sendPitchBend(-2949,channel);
  else 
    MIDI.sendPitchBend(0,channel);
  if (pitch == 62)
  MIDI.sendPitchBend(-2949,channel);
}