refactored emailing so it can handle new data and updating old data