Modify unpacking algorithm