Encoding stuff + More housekeeping

Adding encoding code to the protocol packets