Optimize waitforpacket