         //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
+      //when looping to detect the transition in middle of bit waveform it must never take too long
       if(loopCount>timeout){
-        noErrors=false;
+        noErrors=false;//not allowed to sync on an incorrect transition
+        //if in the header phase and looking for the sync 0 
         if ((!firstZero)&&(headerHits>headerBits)){
-          //Serial.println(loopCount,DEC);
-          polarity = polarity^1;
+          //ending here means the zero was found but polarity was wrong
+          //Serial.println(loopCount,DEC);//enable for debugging
+          polarity = polarity^1;//switch polarity and try for next packet
           //Serial.print("Polarity now =");
           //Serial.println(polarity,DEC);
         }

byte    timeout       ;    //Maximum loops allowed to look for the next bit transition 
byte    loopCount     ;    //Incremented inside the loop looking for next bit transition
//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
boolean firstZero  = false;//has it processed the first zero yet?  This a "sync" bit.
//Variables for Byte storage
byte    discards   = 0;    //how many leading "bits" need to be dumped, usually just a zero if anything eg discards=1
byte    dataByte   = 0;    //Accumulates the bit information

  if (seconds == 300){//make 300 for each output ie 5 minutes
    sDelay = sDelay+10;
    seconds = 0;
    Serial.print("Nos Hits =");//Number of successful Hex dumps (not necessarily fre of errors)
    Serial.println(nosHits,DEC);
    nosHits=0;
    Serial.print("sDelay =");//So the progress of the increments on sDelay can be monitored
    Serial.println(sDelay,DEC);
    lDelay = sDelay*2;//Assume the sampling delays are ratio 1:2
    timeout=lDelay/5; //Rough number to indicate max loops allowed, if exceeded usually wrong polarity chosen, heals itself if wrong
  }
} //end of interrupt routine

