refactor unpack.go

refactor of the functionality, breaking
out some of the deep nesting into
separate functions.