improve email validation and remove code duplication in handling validation errors