refine login logic