Added email validation. Code cleanup also.