events and api refactoring