refactoring login and testing same