improving login logic