refactor to make register_listener a public api