     File root = SD.open("/");
     printlnToSerial("Files: ");
     while (true) {
+
+        if(fileCount > RANDOM_FILE_ARRAY_SIZE){
+            break;
+        }
+
         File entry = root.openNextFile();
         if (!entry) {
             break;
         }
+
         if (!entry.isDirectory()) {
-            char* fileName = entry.name();
+            char *fileName = entry.name();
             printlnToSerial(fileName);
             filesToPlay[fileCount] = fileName;
             fileCount++;
         }
-        if (entry) {
-            entry.close();
-        }
+        entry.close();
     }
 
     root.close();

        Serial.println(ifsh);
    }
}
const float volumeFactor = 255/1024;

void loop() {

    int currentVolumeInputValue = analogRead(VOLUME_INPUT);
    if (abs(currentVolumeInputValue - volumeInputValue) > VOLUME_TOLERANCE) {
        digitalWrite(STATUS_LED, LOW);
        volumeInputValue = currentVolumeInputValue;
        uint8_t volume = volumeFactor * volumeInputValue;
        musicPlayer.setVolume(volume, volume);
        printlnToSerial("Volume: " + String(volumeInputValue));
        digitalWrite(STATUS_LED, HIGH);
        delay(20);
    }

    while (digitalRead(BUTTON_ONE) == HIGH) {
        delay(40);
        if (digitalRead(BUTTON_ONE) == HIGH) {

            if (musicPlayer.playingMusic) {
                musicPlayer.stopPlaying();
            }
            const char* nextFileName = filesToPlay[random(fileCount)].c_str();
            if (!musicPlayer.startPlayingFile(nextFileName)) {
                printlnToSerial("Error: could not play file: " + String(nextFileName));
                Blink(STATUS_LED, 2, 50, 100);
            } else {
                digitalWrite(STATUS_LED, HIGH);
            }
            delay(10);
        }
    }
