improve login fuction