refactor email module.