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

      state = lock(!state);
      digitalWrite(STATUS_LED,LOW);
      delay(100);

      for(i=0;i<TOTAL_SLOTS;i++){ // Usefull to know the slot in which the card
                                  //  is saved :) 
        if(check_card(uid,i))
          blink_n_times(i+1,STATUS_LED);
      }
    }else{
      #ifdef DEBUG
      Serial.println("Access Denied");

  }


  if(!digitalRead(LOCK_UNLOCK)){// Select slot
    state = lock(!state);
  }
  if(!digitalRead(RESET_MEMORY)){// Select slot
    digitalWrite(STATUS_LED,HIGH);
    delay(5000);
    digitalWrite(STATUS_LED,LOW);
    if(!digitalRead(RESET_MEMORY)){
      clear_memory();
      blink_n_times(4,STATUS_LED,100);
      delay(1000);
    }
  }
}

int check_card(uint8_t *uid){
  /* 
   *  Checks if card is saved, returns the address of the card if it saved
   *  or -1 if it is not found.
   */
  int i,j;
  int memory_offset;

  for(i=0;i<TOTAL_SLOTS;i++){
    memory_offset = i*SLOT_SIZE;
    for(j=0;j<SLOT_SIZE;j++){
      if(EEPROM.read(memory_offset+j)!=uid[j]) break;
    }
    if(j==SLOT_SIZE){
      return i;
    }
  }
  return -1;
}
int save_card(uint8_t *uid){
  /* 
   *  Saves card to empty slot
   */
  uint8_t blank_card[] = {0,0,0,0};
  int card_addr = check_card(uid);// Search card
  int i, new_addr, memory_offset;
  if(card_addr == -1){
    new_addr = check_card(blank_card);// Search for a empty slot
    if(new_addr != -1){
      memory_offset = SLOT_SIZE*new_addr;
      for(i=0;i<SLOT_SIZE;i++){
        EEPROM.write(memory_offset+i,uid[i]);
      }
    }
    return new_addr;
  }
  return -1;// Already saved

}
int delete_card(int addr){
  /* 
   *  Deletes card from memory slot (addr)
   */
  int memory_offset = SLOT_SIZE*addr;
  int i;

  for(i=0;i<SLOT_SIZE;i++){
    EEPROM.write(memory_offset+i,0);
  }
}
void clear_memory(void){
  int i;
  int total = TOTAL_SLOTS*SLOT_SIZE;
  for(i=0;i<total;i++){
    EEPROM.write(i,0);
  }
}
void blink_n_times(int n,int led_pin,int blink_interval){
  /*
   * Blink led_pin n times for blink_interval
   */
  int i;
  for(i=0;i<n;i++){
    digitalWrite(led_pin,HIGH);
    delay(blink_interval);
    digitalWrite(led_pin,LOW);
    delay(blink_interval);
  }
}

