Adding some logic to avoid duplicated email address and user names.
Adding more unit test and some small re-factoring.