odd behivor of loop function

ckiick:

  1. You don't have to do both serial.available and serial.read. serial.read will return -1 if no data is available.

I don't think that's good advice. You should be in the habit of checking for bytes being available before you read them.

I expect the original problem was caused by the fact that the Arduino can read received characters from the UART quicker than the UART receives them over the serial line. From the Arduino's point of view the characters are received extremely slowly and you would not expect to receive a lot of characters in one go unless you had waited for them all to be received.