Refactored the email library