more factor out of login code