improve login code