Refactor the protocol + javadoc for some classes. Not finished yet, see TODO.