refactored the events management