added email code and tests