after taking up the iterative approach and sorting out all of the little bugs I was finally able to get the right value
This idea relies on the fact that the packets are sequenstial as opposed to being recursive. To make it work I need to make the whole packet processing process a function and pass in the subpackets in