Correct unpack procedure
Add type check