refactor emails.py