The trick is the LM1 - this uses the note number in M1 to index into the L array to store and retrieve the velocity value per note
Will work on all channels but if same note overlaps on multiple channels off velocity will indeed be that of most recent note on for that specific note. Unlikely on a live instrument. Solution would be to index into the W array with channel+note - left as an exercise!