Fix bugs in rpc protocol