         flash = !flash;
         delay(250);   // Delay 250ms
       }
-      // If the object left exit the loop
+      digitalWrite(Red_Led, HIGH);
+      // If the object, left exit the loop
       if(digitalRead(Sensor_Pin))
         break;               
     }
     get_UID();
-    // ****************************************************************
-    //  Just so it can easily be seen...
-    // Send UID to database to see if card is authorized
-    // ****************************************************************
-
-    //authorized = checkAuthorization();
-    authorized = cheatAuthorization2();
-
-    if(authorized) {
-      Serial.print("Maaa!!!!! I did it!!! (Authorized user) \n");
+    authorized = checkAuthorization();
+
+    if(authorized == false)
+    {
+      bool flash = true; 
+      while(authorized == false)
+      {
+        Serial.println("Please try scanning again or Please leave the spot.");
+        while(!digitalRead(Sensor_Pin) && readCard())
+        {
+          digitalWrite(Red_Led, flash);
+          flash = !flash;
+          delay(250);
+        }
+        digitalWrite(Red_Led, HIGH);
+        // If the object, left exit the loop
+        if(digitalRead(Sensor_Pin))
+          break;
+        get_UID();
+        authorized = checkAuthorization();   
+//        delay(200);
+//        break;
+      }
+    }
+    if(authorized == true) {
       digitalWrite(Red_Led, LOW); // Shutoff Red LED for flashing sequence
       flash_LED(Green_Led, 2000); // Flash LED for 2 seconds
-      digitalWrite(Green_Led, LOW); // Shutoff Green LED
       digitalWrite(Red_Led, HIGH);  // Turn on RED LED to signal occupied
-      Serial.print("Time to wait for Michael to move his car...\n");
+      Serial.print("Waiting for user to move their vehicle...\n");
       while(!digitalRead(Sensor_Pin))
       {
         delay(500); // check the pin every 500ms to avoid WDT reset
-      }
-    }
-    else // If they are not authorized...
-    {
-      Serial.print("Don't tell Maaa!!!! (Unauthorized user) \n");
-      bool flash = true;
-      while(!digitalRead(Sensor_Pin)) 
-      {
-        digitalWrite(Red_Led, flash);
-        flash = !flash;
-        delay(250);
-      }
-    }
-  }
-  if(flag == true) {
-    Serial.print("Guess they left... (Object no longer detected)\n");
-    Serial.print("Updating spot vacancy to true...");
+      }     
+//      delay(200);
+//      break; 
+    }
+  
+  }
+  if(vacancyFlag == true) {
+    Serial.println("User has left the spot. Updating spot vacancy.");
+    updateVacancy("true");
     Serial.println();
-    while(!updateVacancy(true)) {
-      delay(100);
-    }
-    delay(500);  // Delay for 1/2 Second
-  }
-  delay(250); // Check for card every 250ms to avoid WDT resets
+    Serial.println("Waiting for spot to become occupied...");
+  }
+  delay(100); // Check for card every 100ms to avoid WDT resets
 }
 
 ////////////////////////////////////////////////////////////////////////////////////////////////

  // Code to setup esp8266 to connect to zee weefee 
  delay(100);
  WiFi.begin(weefee_ID, weefee_Password);
  Serial.print("Connecting to ze network...");
  while (WiFi.status() != WL_CONNECTED) {
    //Serial.print(".");
    delay(500);
  }
  Serial.println();
  Serial.print("connected: ");
  Serial.println(WiFi.localIP());
}

// Reads the Unique ID from the card and stores it as a 32-bit unsigned integer


MFRC522 mfrc522(SELECTOR_PIN, RESET_PIN);
MFRC522::MIFARE_Key key;
//////////////////

unsigned int UID = 0;
unsigned long start_time = 0;
unsigned long timer = 0;
unsigned int timeLimit = 20000;  // Time in milliseconds for sign in
unsigned int success = 0;
unsigned int failure = 0;

// URL for server communications must be added here
RestClient client = RestClient("unlv-spots.herokuapp.com");

bool vacancyFlag;
bool authorized;

// List of all the beautiful functions used for this immaculate device
void Wifi_connect();    // Setup code to connect the ESP8266 to the wifi_chip
void get_UID();         // Function to read the data UID from a card
void flash_LED();
bool readCard();        // Convenience Function to read a card
bool checkAuthorization();  // Check if the user is authorized
String createPath(String);  // Creates the path for rest calls
bool updateVacancy(String);    // Update the server of a spot vacancy

void setup() {
  Serial.begin(9600);
  Wifi_connect();
  SPI.begin(); 
  mfrc522.PCD_Init();
  // Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
  for (byte i = 0; i < 6; i++) {
    key.keyByte[i] = 0xFF;    
  }
   
  pinMode(Green_Led, OUTPUT);
  pinMode(Red_Led, OUTPUT);
  pinMode(Sensor_Pin, INPUT);
  Serial.println("Welcome to SPOTS!");
  Serial.println("Setting the lot to vacant as part of boot sequence...");
  updateVacancy("true"); // Set the vacancy of the spot to true at startup
  Serial.println("Waiting for spot to become occupied...");
}

void loop() {
