Initial implemention of the protocol

Needs code cleanup and thinking of what to put to where etc.