       //  Just so it can easily be seen...
       //  Update database of timeOut
       // ****************************************************************
+      // Kind of an odd workaround...
+      // Logic here is that they either didn't scan a card... or took too long
+      // Thus we send an authorization request with a UID that is guaranteed to not
+      // be valid, this updates the server of an invalid parking at that spot...
+      // At least... that's my thought process...
+//      UID = 0;
+//      authorized = checkAuthorization();
+//    ****** Note.... I'm not even sure this is needed... I highly doubt it but eh...
+      
       bool flash = true;
-      while(digitalRead(Sensor_Pin) || readCard()) 
+      while(!digitalRead(Sensor_Pin) && readCard()) 
       {
         digitalWrite(Red_Led, flash);
         flash = !flash;
         delay(250);   // Delay 250ms
-      }         
+      }
+      // 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");
-      flash_LED(Green_Led, 120000); // Flash LED for 2 seconds
+      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");
+      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)) 
+      while(!digitalRead(Sensor_Pin)) 
       {
         digitalWrite(Red_Led, flash);
         flash = !flash;
+        delay(250);
       }
     }
   }
-  Serial.print("Guess they left... (Object no longer detected)\n");
-  // ****************************************************************
-  //  Just so it can easily be seen...
-  // Update Database of vacancy
-  // ****************************************************************
-  delay(1000);  // Delay for 1 Second
+  if(flag == true) {
+    Serial.print("Guess they left... (Object no longer detected)\n");
+    Serial.print("Updating spot vacancy to 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
 }
 
 ////////////////////////////////////////////////////////////////////////////////////////////////

unsigned long start_time = 0;
unsigned long current_time = 0;
unsigned long timer = 0;
unsigned int timeLimit = 300000;  // Time in milliseconds for sign in
String response;
bool cardPresent = false;
bool authorized = false;

// 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

void setup() {
  pinMode(Sensor_Pin, INPUT);

  digitalWrite(LED, LOW);
}

// Returns true if no card is being read, false otherwise
bool readCard() {
  return ( (!mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) );
}

// Cheating test function that tests authorization of current card
bool cheatAuthorization() {
  if(UID == 0x647B403B)
    return true;
  else
    return false;
}

bool cheatAuthorization2() {
  Serial.print("Attempting to cheat Authorization...\n");
  if(UID == 0x647B403B){
    UID = 12345678; // This is a staff ID#
    Serial.print("Authorization should be set to True\n");
    return (checkAuthorization());
  }
  else {
    Serial.print("Authorization should be set to False\n");
    return false;
  }
}

// Generates a path to be used for the post and get API commands
// The command field should either be the string "swipe" or "update"
// A string containing the path to be updated is returned...
// Returned string looks like the following
// "/command/key/lotID/spotID/"
String createPath(String command)
{
  String tempPath;
  String spotsHW = "/spotsHW";
  tempPath =  spotsHW + '/' + command + '/' + apiKey + '/' + lotID + '/' + spotID + '/';
//  Serial.print("Generated path: ");
//  Serial.print(tempPath);
//  Serial.println();
//  delay(100);
  return tempPath;
}

// Updates the vacancy of the spot with the server
// If the spot is not occupied, set vacant = true;
// else, set it to false
bool updateVacancy(bool vacant)
{
  String updatePath = createPath("update");
  const char * c;
  int statusCode;
  response = "";
  
  if(vacant) {
    updatePath = updatePath + "true";
  }
  else {
    updatePath = updatePath + "false";
  }

  c = updatePath.c_str();
  Serial.print("Generated path: ");
  Serial.print(c);
  Serial.println();
  delay(10);
  // This is done in this way because client.post requires a const char* for the path...
  // client.post(const char* path, const char* body, String* response)
  statusCode = client.post(c, "POSTDATA", &response);
  Serial.print("Status code from server: ");
  Serial.println(statusCode);
  Serial.print("Response body from server: ");
  Serial.println(response);
  delay(10);
  if(statusCode == 200) // Status Code 200 means "OK"
    return true;
  else
    return false;
}

// Checks the whether the user was authorized
// Returns true if the user is authorized,
// false otherwise.
bool checkAuthorization()
{
  String swipePath = createPath("swipe");
  // UID is a global variable that contains the integer representation of the card ID
  String cardID = String(UID);
  swipePath = swipePath + cardID;
  const char * c;
  int statusCode;
  int len;
  
  c = swipePath.c_str();
  Serial.print("swipePath: ");
  Serial.print(c);
  Serial.println();
  statusCode = client.post(c, "POSTDATA", &response);
  Serial.print("Status code from server: ");
  Serial.println(statusCode);
  Serial.print("Response body from server: ");
  Serial.println(response); 
  delay(10);

  // Search the response string for "true" to see if user is authorized
  len = response.length();
  for(int i = 0; i <= len; i++) {
    if(response.substring(i, i + 4) == "true")
      return true;
  }
  // if we can't find "true" in the response string, user is not authorized...
  return false;
}
