Improve login logic