refactor midi message handler