Move all rpc code into utils