Improved event handling