Flushing Arduino

  type=1;
  error=0;
  if(error==0)
  {
    if(type==1)
    {
      // blah
    }

  }

Could certainly be simplified to:

// blah

... it started giving previous output along with present one ...

Maybe your code had a bug? You could simplify it.