Refactor and fix bug that could cause a loss of MIDI input