Refactored the event source handling