Get command from serial

You are reading from the serial receive buffer before you know that there is anything in the buffer to read. I suggest that you check out the serial input basics tutorial.