WIP: protocol layer
more stuff for protocol layer
move helper functions to common.js