fix bugs when packing