rewrite of code to remove noteoffs