Code refactoring - Refine send_events() function