Moved email-writing code, and added CSV creation