 }
 
 void loop() {
-  if (musicPlayer.playingMusic) {
+
+  if (playing && musicPlayer.playingMusic) {
     musicPlayer.feedBuffer();
-  } else if(playing) {
+  } else if (playing) {
     playMp3();
   }
 
+  handleRfid();
   server.handleClient();
-
 }
 
 void handleRfid() {
-    // Look for new cards
+  // Look for new cards
   if ( ! mfrc522.PICC_IsNewCardPresent()) {
     return;
   }

}

void switchFolder(const char *folder) {
  // TODO do SD.exists(folder) check here, but it keeps crashing the ESP
  Serial.print(F("Switching folder to "));
  Serial.println(folder);
  currentFolder.close();
  currentFolder = SD.open(folder);
}

void stopMp3() {
    playing = false;
    musicPlayer.stopPlaying();
}

void playMp3() {
  while (File file = currentFolder.openNextFile())
  {

    char filename[30] = "";
    strcat(filename, "/");
    strcat(filename, currentFolder.name());
    strcat(filename, "/");
    strcat(filename, file.name());
    file.close();

    if(!file.isDirectory() && isMP3File(filename)){ 
      Serial.print(F("Playing "));
      Serial.println(filename);

      playing = true;
      musicPlayer.startPlayingFile(filename);
      return;
    } else {
      Serial.print(F("Ignoring "));


  // Show some details of the PICC (that is: the tag/card)
  Serial.print(F("Card UID:"));
  print_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
  Serial.println();
  Serial.print(F("PICC type: "));
  MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
