Move some of the login process out of the main class.