   }
   String password = webServer.arg("password");
 
+  wifiStatus = -1;
+  webServer.send(200, "text/plain", "");
+  delay(1000);
   if (password == "")
   {
     WiFi.begin(ssid.c_str());
   } else {
     WiFi.begin(ssid.c_str(), password.c_str());
   }
-  webServer.send(200, "text/plain", "");
-  Serial.println("config done");
 }
 
 void getWiFiStatus()
 {
-  int status = WiFi.status();
-  Serial.println("got status");
-  Serial.println(status);
-  switch(status)
+  if (wifiStatus == -1)
   {
-    case WL_DISCONNECTED:
-      webServer.send(202, "text/plain", "");
+    wifiStatus = WiFi.waitForConnectResult();
+  }
+  switch(wifiStatus)
+  {
+    case WL_CONNECTED:
+      webServer.send(200, "text/plain", "");
+      saveConfig();
       return;
-    case WL_CONNECTED:
-    {
-      saveConfigAndRestart();
-      shouldRestart = millis();
-      Serial.println("Count start");
-      webServer.send(200, "text/plain", "Success.");
-      return;
-    }
     case WL_NO_SSID_AVAIL:
-    {
-      String ssid = webServer.arg("ssid");
-      ssid.trim();
-      webServer.send(503, "text/plain", "Could not find a WiFi network named \""
-      + ssid + "\". Please check your input and try agian.");
+      webServer.send(503, "text/plain", "Could not find specified WiFi network."
+      " Please check your input and try again.");
       break;
-    }
     case WL_CONNECT_FAILED:
     case WL_CONNECTION_LOST:
       webServer.send(503, "text/plain", "Unable to connect to WiFi. Please make"


void configurationSetup() {
  Serial.begin(115200);
  Serial.println();

  WiFi.mode(WIFI_AP_STA);

  WiFi.disconnect();
}

void saveConfig()
{
  EEPROM.begin(1);
  EEPROM.write(0, (int)BootMode::Sensor);
