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

   gpio 14 - pin 5 on header

*/
#define SONOFF_BUTTON    0
#define SONOFF_RELAY    12
#define SONOFF_LED      13

  shouldSaveConfig = true;
}


void toggle() {
  Serial.println("toggle state");
  Serial.println(relayState);
  relayState = relayState == HIGH ? LOW : HIGH;
  setState(relayState);
}

void restart() {
  ESP.reset();
  delay(1000);
}

void reset() {
  //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);
}


//off - button
BLYNK_WRITE(0) {
  int a = param.asInt();
  if (a != 0) {
    turnOff();
  }
}

//on - button
BLYNK_WRITE(1) {
  int a = param.asInt();
  if (a != 0) {
    turnOn();
  }
}

//toggle - button
BLYNK_WRITE(2) {
  int a = param.asInt();
  if (a != 0) {
    toggle();
  }
}

//restart - button
BLYNK_WRITE(3) {
  int a = param.asInt();
  if (a != 0) {
    restart();
  }
}

//restart - button
BLYNK_WRITE(4) {
  int a = param.asInt();
  if (a != 0) {
    reset();
  }
}

//status - display
BLYNK_READ(5) {
  Blynk.virtualWrite(5, relayState);
}

void setup()
{
  Serial.begin(115200);
