Refactor event listeners