refactor and fixes to email