Refactoring code in the email sender and SendGrid API.