Fix and refactor login/registration