improve login function