Added encoding of packets