       noErrors=false;//something has gone wrong, polarity has changed too early, ie always an error
     }//exit and retry
     else{
+      //now grab the bitState before setting up for next bit & correct for polarity
+      bitState = tempBit ^ polarity;//Polarity=1, invert OR Polarity=0, ignore
+      //Now work on what the next bit waveform is going to be 
       delayMicroseconds(lDelay);
       //now 1 quarter into the next bit pattern,
-      if(digitalRead(RxPin)==tempBit){ //if RxPin has not swapped, then bitWaveform is swapping
+      if(digitalRead(RxPin)==tempBit){ //if RxPin has NOT swapped, then next data bit value IS swapping
         //If the header is done, then it means data change is occuring ie 1->0, or 0->1
-        //data transition detection must swap, so it loops for the opposite transitions
+        //data transition detection must swap, so it loops for the opposite transition in the next bit waveform
         tempBit = tempBit^1;
-      }//end of detecting no transition at end of bit waveform, ie end of previous bit waveform same as start of next bitwaveform
-
-      //Now process the tempBit state and make data definite 0 or 1's, allow possibility of Pos or Neg Polarity 
-      byte bitState = tempBit ^ polarity;//if polarity=1, invert the tempBit or if polarity=0, leave it alone.
+      }//end of detecting no transition at end of bit waveform
+
+      //Now process the tempBit state and interept data as definite 0 or 1's, (Polarity corrected by now) 
       if(bitState==1){ //1 data could be header or packet
         if(!firstZero){
           headerHits++;

int ledPin          = 13;  //The number of the onboard LED pin

// Variables for Manchester Receiver Logic:
word    sDelay     = 250;  //Small Delay about 1/4 of bit duration  try like 250 to 500
word    lDelay     = 500;  //Long Delay about 1/2 of bit duration  try like 500 to 1000, 1/4 + 1/2 = 3/4
byte    polarity   = 1;    //0 for lo->hi==1 or 1 for hi->lo==1 for Polarity, sets tempBit at start
byte    tempBit    = 1;    //Reflects the required transition polarity
byte    discards   = 0;    //how many leading "bits" need to be dumped, usually just a zero if anything eg discards=1
boolean firstZero  = false;//has it processed the first zero yet?  This a "sync" bit.
boolean noErrors   = true; //flags if signal does not follow Manchester conventions
//variables for Header detection
byte    headerBits = 15;   //The number of ones expected to make a valid header
byte    headerHits = 0;    //Counts the number of "1"s to determine a header
//Variables for Byte storage
byte    dataByte   = 0;    //Accumulates the bit information
byte    nosBits    = 0;    //Counts to 8 bits within a dataByte
byte    maxBytes   = 9;    //Set the bytes collected after each header. NB if set too high, any end noise will cause an error
byte    nosBytes   = 0;    //Counter stays within 0 -> maxBytes
//Variables for multiple packets
byte    bank       = 0;    //Points to the array of 0 to 3 banks of results from up to 4 last data downloads 

          //we have our header, chewed up any excess and here is a zero
          if ((!firstZero)&&(headerHits>=headerBits)){ //if first zero, it has not been found previously
            firstZero=true;
            //Serial.print("!");
          }//end of finding first zero
          add(bitState);
        }//end of dealing with a zero
