minor code improvement to add events in a loop