updated emailing code