fixed email generation.
cleaned some code.