improve login function
refactoring