refactored the start of the login function