Small refactor on the event handler