added logic for sorting events based on order priority