Refactoring event listener