updated encoding and packing of data