refine logic for email notifications