optimizes event handling