Refactor

Here's a bunch of little things to help refactor the protocol generator.