refactored email downcast code