Added packetAvailable check