Improved login handling