more factor out of login code for RPC