login logic optimized