some good progress towards the email templating function