Improve handling of login/logout some more to improve the chances of