Some fixes in packing algorithm