Arduino serial communication synchronisation
I suspect you problem stems from the use of delay's in your code. for example,

if (data=='1')
 {
  digitalWrite(13,HIGH);
  delay(4000);
  digitalWrite(13,LOW);
  delay(4000);
 } 


Those delays prevent any computations from happening for 4 seconds each. Your arduino will not read another character after it sees a '1' for 8 seconds. If you send too much data in that 8 seconds to fit in the serial buffer, the extra characters are lost.

The behavior you seem to want will require separating the code that reads serial from the code that runs the output, and making sure neither section ever stops execution with delays. Your blinks will need to be timed with something else, like frequent comparisons against the current time with millis()