Misc refactor

This fixes some miscellaneous issues I saw while doing other things, mostly from static analysis via Pylint.
I'd much prefer importing `protocol` and using it as a namespace - I find it far more readable throughout the rest of the code...