Lots of protobuf/rpc code and some refactoring