Fixes some bugs in unpacking