setEvents code refactoring