Added check that packet is longer than the minimum length
Reduced the amount of duplicated code in the packet header parsing