     nfc.PrintHex(uid, uidLength);
     Serial.println("");
     #endif
-    for(i=0;i<TOTAL_SLOTS;i++){ //Check all memory slots
-      if(check_card(uid,i))
-        access_granted = 1;
-    }
+    memory_slot = check_card(uid);
+    access_granted = (memory_slot == -1) ? 0 : 1;
+    
     if(save_delete){
       access_granted = 0; //Reset Access
       #ifdef DEBUG
       Serial.println("Continue pressing to save or delete card");
       #endif
       delay(3000);
-      if(!digitalRead(MEMORY_BUTTON)){
-        if(save_delete_card(uid,memory_slot)){
+      if(!digitalRead(SAVE_CARD)){
+        if(memory_slot == -1){
+          memory_slot = save_card(uid);
           #ifdef DEBUG
           Serial.print("Save Card Slot: ");
-          Serial.println(memory_slot);
+          Serial.println(memory_slot+1);
+          blink_n_times(memory_slot+1,STATUS_LED,250);
+          delay(1000);
           #endif
-          blink_n_times(memory_slot+1,STATUS_LED);
+          blink_n_times(3,STATUS_LED,100);
         }else{
+          delete_card(memory_slot);
           #ifdef DEBUG
-          Serial.println("Delete Card");
+          Serial.println("Card deleted!");
           #endif
-          digitalWrite(STATUS_LED,HIGH);
-          delay(2000);
-          digitalWrite(STATUS_LED,LOW);
+          blink_n_times(1,STATUS_LED,2000);
         }
       }
     }

  }


  
  if(!digitalRead(SLOT_SELECT)){// Select memory slot
    while(!digitalRead(SLOT_SELECT));
    memory_slot = (memory_slot < TOTAL_SLOTS - 1) ? memory_slot + 1 : 0;
    #ifdef DEBUG
    Serial.print("Slot selected: ");
    Serial.println(memory_slot);
    #endif
    blink_n_times(memory_slot+1,STATUS_LED);
  }
  if(!digitalRead(LOCK_UNLOCK)){// Select slot
    state = lock(!state);
  }
}

boolean save_delete_card(uint8_t *uid,int addr){
  /*
   * If card doesn't exist in any slot, then it is saved in "addr", 
   *   else it is deleted from memory.
   */
  int i;
  int j;
  int memory_offset = SLOT_SIZE*addr;
  boolean save = 1;
  
  for(i=0;i<TOTAL_SLOTS;i++){ //Check if card is saved in any slot
    if(check_card(uid,i)){
      save = 0; //Delete if found
    }
  }
  if(save){
    for(i=0;i<SLOT_SIZE;i++){
      EEPROM.write(memory_offset+i,uid[i]);
    }
    return(1);
  }else{
    for(i=0;i<TOTAL_SLOTS;i++){ //Delete card from all slots
      if(check_card(uid,i)){
        memory_offset = SLOT_SIZE*i;
        for(j=0;j<SLOT_SIZE;j++){
          EEPROM.write(memory_offset+j,0);
        }
      }
    }
    return(0);
  }
}
boolean check_card(uint8_t *uid,int addr){
  /* 
   *  Checks if card (uid) is contained in the designed address (addr)
   */
  int i;
  int memory_offset = SLOT_SIZE*addr;
  for(i=0;i<SLOT_SIZE;i++){
    if(EEPROM.read(memory_offset+i)!=uid[i]) return 0;
  }
  return 1;
}
void blink_n_times(int n,int led_pin){
  /*
   * Blink n times
   */
  int i;
  for(i=0;i<n;i++){
    digitalWrite(led_pin,HIGH);
    delay(250);
    digitalWrite(led_pin,LOW);
    delay(250);
  }
}


void loop(void) {
  uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
  int tmp_addr;
  uint8_t uidLength;    // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
  int i,j;
  boolean save_delete = 0;
