event handling using a priority queue