Updated packet parsing function.