Cleanup and move mail functionality to a class