Improved the `unpack` function

I think this is a simpler and more efficient