restructured to handle length field fragmentation