refactored email controller