Adding support for email templates.
Minor refactoring.