refactored some mail stuff