Improve event handling