Fixed many bugs, separated protocol operations into new header.