Refactored most of the code in mail.py and extended db_interface.py