refine login code