Add to protocol

Refactor out the bit twiddling and add additional bits from o ther parts