Update unpack script and fix a few bugs in it