some refactoring of user reg and login