added debug tracing and corrected unpack issue