refactor email manager