Fixed endless loop

Fixed an issue with an endless loop after while loop packet structure