Some refactoring to user registration