Event handling refactoring