Event refactoring and unit tests