Refactoring for event-driven API