Some general cleanup and fixes around the login process