added check for duplicate emails and error handling in the rest endpoint