final refactoring of login