fix update email and refactor code