Improve error handling with emails
Add email test option. Also fix some bugs.