Merge testing branch, bringing in refactor etc.

- Code cleanup
- E-mail functionality improvement