Improved the login/logout loop