Refactored email controller