refacor the login