improved event handling