Improved PacketStructure

To avoid creating a function on each new instance, and moved functions
inside loops, outside.