Refactor event registration.