improved login code