Legato synth problems?

I am attempting to make a mono synth with a Legato capability but am having some problems dealing with note-offs.

I press the first note and get the (note number+velocity) list, press the second note (note number+velocity), then release the first note and the 0 velocity message acts as a note off for all notes held down. What I want is for a note off to register only if it has the same note number as the last note on message.

I have tried using a Sel object with the value being set by each note on and the value of any received note offs being used to compare but this doesn’t work at all and am having trouble understanding why?

This is the patch that I am having trouble with.

Any help would be hugely appreciated.

Cheers

-- Pasted Max Patch, click to expand. --

Copy all of the following text. Then, in Max, select New From Clipboard.