Partial work.

This is just a snapshot of me overhauling the code like crazy.

Have to redo some code since apparently you're not supposed to use the
static inline functions in the *-protocol.h header files.