Refactor event handlers