       break;
     case CMD_BUTTON_CHANGE:
       int currentState = digitalRead(SONOFF_BUTTON);
-      if (currentState != state) {
-        if (state == LOW && currentState == HIGH) {
+      if (currentState != buttonState) {
+        if (buttonState == LOW && currentState == HIGH) {
           long duration = millis() - startPress;
           if (duration < 1000) {
             Serial.println("short press - toggle relay");
-            relayState = !relayState;
-            setState(relayState);
+            toggle();
           } else if (duration < 5000) {
             Serial.println("medium press - reset");
-            ESP.reset();
-            delay(1000);
+            restart();
           } else if (duration < 60000) {
             Serial.println("long press - reset settings");
-            //reset settings to defaults
-            /* 
-            WMSettings defaults;
-            settings = defaults;
-            EEPROM.begin(512);
-            EEPROM.put(0, settings);
-            EEPROM.end();
-            */
-            //reset wifi credentials
-            WiFi.disconnect();
-            delay(1000);
-            ESP.reset();
-            delay(1000);
+            reset();
           }
-        } else if (state == HIGH && currentState == LOW) {
+        } else if (buttonState == HIGH && currentState == LOW) {
           startPress = millis();
         }
-        state = currentState;
+        buttonState = currentState;
       }
       break;
   }

  //ota loop
  ArduinoOTA.handle();
  //blynk connect and run loop
  if(BLYNK_ENABLED) {
    Blynk.run();
  }
  //delay(200);

const int CMD_BUTTON_CHANGE = 1;

int cmd = CMD_WAIT;
int relayState = HIGH;

//inverted button state
int buttonState = HIGH;

static long startPress = 0;

void tick()
{
