Cleaned up the image-packing code.