Improved event handling.