code refactoring for events