Fix infinite loop on big packets; cleanup.