cope with sending email issue with reset password feature and refactoring code