 
 void falling() {
     attachInterrupt(0, rising, RISING);
+
+    //remember current time
+    //it will be used in raising function
     prev_time_falling = micros();
 
+    //calc length of last HIGH pulse
     pwm_high_length = micros() - prev_time_rising;
 
     if (state % 2 == 0) {
+        //We only can proceed is thate is even: 0, 2, 3 - after this state
+        //we always expect divider HIGH pulse to happen
         setState(state + 1, matchDivider(pwm_high_length));
     } else {
-        setState(state, false);
+        //Clear state to zero since it happens that we are in invalid state
+        //at this point
+        setState(0, true);
     }
 }
 

        boolean matchOne = matchOneBit(pwm_low_length);
        boolean matchZero = matchZeroBit(pwm_low_length);

        setState(newState, matchOne || matchZero);

        if (state == newState) {
            int bitNumber = (state - 1) / 2 - 1;
            fillDataArray(bitNumber, matchOne);

            if (bitNumber == DATA_BITS_AMOUNT - 1) {
                printDataArray();
                setState(state, false);
            }
        }
    }


void fillDataArray(byte bitNumber, boolean isOne) {
    byte dataArrayIndex = bitNumber / BITS_PER_PACKET;
    boolean isFirstBitInTetrad = bitNumber % 4 == 0;

    if (isFirstBitInTetrad) {
        //clear tetrad since it could be filled with random data
        data[dataArrayIndex] = 0;
    }

    data[dataArrayIndex] = (data[dataArrayIndex] << 1) | isOne;
}

// Matcher for divider bit
boolean matchDivider(int value) {
    return match(value, DIVIDER_PULSE_LENGTH, DIVIDER_THRESHOLD);
}

// Matcher for start bit
boolean matchStartBit(int value) {
    return match(value, START_BIT_LENGTH, START_BIT_THRESHOLD);
}

// Matcher for binary 1
boolean matchOneBit(int value) {
    return match(value, BIT_1_LENGTH, REGULAR_BIT_THRESHOLD);
}

// Matcher for binary 0
boolean matchZeroBit(int value) {
    return match(value, BIT_0_LENGTH, REGULAR_BIT_THRESHOLD);
}

//Whether pulse length value matches specified constant with specified threshold
boolean match(int value, int mathConst, int treshold) {
    return value > mathConst - treshold && value < mathConst + treshold;
}

//set state to new value but only when condition is true
void setState(byte st, boolean condition) {
    state = condition ? st : 0;
}



