     delay(normal);
 }
 
+void _outsideInOnInsideOutOffBackground(int times, int endingWithLightsOn, int repeatCount) {
+    backgroundOnOutsideIn();
+    delay(ish);
+
+    if (repeatCount > 0 || !endingWithLightsOn) {
+        backgroundOffInsideOut();
+        delay(ish);
+
+        if (repeatCount > 0) {
+          _outsideInOnInsideOutOffBackground(times, endingWithLightsOn, repeatCount - 1);
+        }
+    }
+}
+
 void outsideInOnInsideOutOffBackground(int times, int endingWithLightsOn) {
-    for (int count = 0; count < times; count++) {
-        backgroundOnOutsideIn();
+  _outsideInOnInsideOutOffBackground(times, endingWithLightsOn, times);
+}
+
+void _insideOutOnOutsideInOffBackground(int times, int endingWithLightsOn, int repeatCount) {
+    backgroundOnInsideOut();
+    delay(ish);
+
+    if (repeatCount > 0 || !endingWithLightsOn) {
+        backgroundOffOutsideIn();
         delay(ish);
-        if (count + 1 != times || !endingWithLightsOn) {
-            backgroundOffInsideOut();
-            delay(ish);
+
+        if (repeatCount > 0) {
+          _insideOutOnOutsideInOffBackground(times, endingWithLightsOn, repeatCount - 1);
         }
     }
 }

void setup() {
    randomSeed(analogRead(0));

    for (int i = 0; i < sizeof(Lights); i++) {
        pinMode(Lights[i], PATTERN_INITIALIZE);
    }
}

// code above the man is ignored by the emulator

    }
}

void _insideOutOutsideInBackground(int repeatCount) {
    if (random(0, 2) == 0) {
        outsideInOnInsideOutOffBackground(random(1, 4), true);
        delay(minimal);

        insideOutOnOutsideInOffBackground(random(1, 4), false);
        delay(minimal);
    } else {
        insideOutOnOutsideInOffBackground(random(1, 4), true);
        delay(minimal);

        outsideInOnInsideOutOffBackground(random(1, 4), false);
        delay(minimal);
    }

    if (repeatCount > 0) {
        _insideOutOutsideInBackground(repeatCount - 1);
    }
}

void insideOutOutsideInBackground() {
  _insideOutOutsideInBackground(random(3, 8));
}

void racingOnLeftToRightBackground() {
    digitalWrite(background[0], PATTERN_ON); delay(minimal);
    digitalWrite(background[0], PATTERN_OFF); delay(none);
    digitalWrite(background[1], PATTERN_ON); delay(minimal);
    digitalWrite(background[1], PATTERN_OFF); delay(none);
    digitalWrite(background[2], PATTERN_ON); delay(minimal);
    digitalWrite(background[2], PATTERN_OFF); delay(none);
    digitalWrite(background[3], PATTERN_ON); delay(minimal);
    digitalWrite(background[3], PATTERN_OFF); delay(none);
    digitalWrite(background[4], PATTERN_ON); delay(minimal);
    digitalWrite(background[4], PATTERN_OFF); delay(none);
    digitalWrite(background[5], PATTERN_ON); delay(minimal);
    digitalWrite(background[0], PATTERN_ON); delay(minimal);
    digitalWrite(background[0], PATTERN_OFF); delay(none);
    digitalWrite(background[1], PATTERN_ON); delay(minimal);
    digitalWrite(background[1], PATTERN_OFF); delay(none);
    digitalWrite(background[2], PATTERN_ON); delay(minimal);
    digitalWrite(background[2], PATTERN_OFF); delay(none);
    digitalWrite(background[3], PATTERN_ON); delay(minimal);
    digitalWrite(background[3], PATTERN_OFF); delay(none);
    digitalWrite(background[4], PATTERN_ON); delay(minimal);
    digitalWrite(background[0], PATTERN_ON); delay(minimal);
    digitalWrite(background[0], PATTERN_OFF); delay(none);
    digitalWrite(background[1], PATTERN_ON); delay(minimal);
    digitalWrite(background[1], PATTERN_OFF); delay(none);
    digitalWrite(background[2], PATTERN_ON); delay(minimal);
    digitalWrite(background[2], PATTERN_OFF); delay(none);
    digitalWrite(background[3], PATTERN_ON); delay(minimal);
    digitalWrite(background[0], PATTERN_ON); delay(minimal);
    digitalWrite(background[0], PATTERN_OFF); delay(none);
    digitalWrite(background[1], PATTERN_ON); delay(minimal);
    digitalWrite(background[1], PATTERN_OFF); delay(none);
    digitalWrite(background[2], PATTERN_ON); delay(minimal);
    digitalWrite(background[0], PATTERN_ON); delay(minimal);
    digitalWrite(background[0], PATTERN_OFF); delay(none);
    digitalWrite(background[1], PATTERN_ON); delay(minimal);
    digitalWrite(background[0], PATTERN_ON); delay(minimal);
}

void _blinkBackgroundPairLeftToRight(int repeatCount) {
    digitalWrite(background[0], PATTERN_ON); delay(none);
    digitalWrite(background[3], PATTERN_ON); delay(minimal);
    digitalWrite(background[0], PATTERN_OFF); delay(none);
    digitalWrite(background[3], PATTERN_OFF); delay(none);

    digitalWrite(background[1], PATTERN_ON); delay(none);
    digitalWrite(background[4], PATTERN_ON); delay(minimal);
    digitalWrite(background[1], PATTERN_OFF); delay(none);
    digitalWrite(background[4], PATTERN_OFF); delay(none);

    digitalWrite(background[2], PATTERN_ON); delay(none);
    digitalWrite(background[5], PATTERN_ON); delay(minimal);
    digitalWrite(background[2], PATTERN_OFF); delay(none);
    digitalWrite(background[5], PATTERN_OFF); delay(none);

    if (repeatCount > 0) {
        _blinkBackgroundPairLeftToRight(repeatCount - 1);
    }
}

void blinkBackgroundPairLeftToRight() {
    blinkBackgroundPairLeftToRight(random(5, 10));
}

void blinkLetters(int times) {
    lettersAllOff();
    delay(blinky);

    lettersAllOn();
    delay(blinky);

    if (times > 0) {
        blinkLetters(times - 1);
    }
}

void blinkBackground(int times) {
    backgroundAllOff();
    delay(blinky);

    backgroundAllOn();
    delay(blinky);

    delay(normal);

    if (times > 0) {
        blinkBackground(times - 1);
    }
}

//void blinkAllOnRandom() {
//    int state[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
//
//    int on = 0;
//
//    while (on != sizeof(state)) {
//        int value = random(0, sizeof(state));
//        if (state[value]) {
//            continue;
//        }
//
//        state[value] = 1;
//        int pin = Lights[value];
//        digitalWrite(pin, PATTERN_ON);
//        on++;
//
//        delay(minimal);
//    }
//}
//
//void blinkBackgroundOnRandom() {
//    int state[] = { 0, 0, 0, 0, 0, 0 };
//
//    for (int i = 0; i < sizeof(state); i++) {
//        state[i] = 0;
//    }
//
//    int on = 0;
//
//    while (on != sizeof(state)) {
//        int value = random(0, sizeof(state));
//        if (state[value]) {
//            continue;
//        }
//
//        state[value] = 1;
//        int pin = background[value];
//        digitalWrite(pin, PATTERN_ON);
//        on++;
//
//        delay(minimal);
//    }
//}
//
//void blinkLettersOnRandom() {
//    // from: int state[] = [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ];   
//    int state[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
//
//    for (int i = 0; i < sizeof(state); i++) {
//        state[i] = 0;
//    }
//
//    int on = 0;
//
//    while (on != sizeof(state)) {
//        int value = random(0, sizeof(state));
//        if (state[value]) {
//            continue;
//        }
//
//        state[value] = 1;
//        int pin = letters[value];
//        digitalWrite(pin, PATTERN_ON);
//        on++;
//
//        delay(minimal);
//    }
//}

void _flickerPattern(int flickerLetters, int flickerBackground, int repeatCount) {
        allOn();

    int max = 0;
    if (flickerLetters == 1) {
