 }
 
 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;
   }


  // Show some details of the PICC (that is: the tag/card)
  Serial.print(F("Card UID:"));
  dump_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);

}

void switchFolder(const char *folder) {
  Serial.print(F("Switching folder to "));
  Serial.println(folder);

  if (!SD.exists(folder)) {
    Serial.println(F("Folder does not exist"));
    return;
  }
  SD.chdir(folder);
  SD.vwd()->rewind();
}

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

void playMp3() {
  SdFile file;
  while (file.openNext(SD.vwd(), O_READ))
  {
    char filenameChar[100];
    String filename = "/";

    SD.vwd()->getName(filenameChar, 100);
    filename += filenameChar;

    filename += "/";
    file.getName(filenameChar, 100);
    filename += filenameChar;

    file.close();

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

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