Improved login and logout behaviour