Added dequeue loop and insertPacket code