refactor eventsHandler