Refactoring query and group code for Weekly Activity email