Refactor/optimize protobuf