 
   // setup the switch
   pinMode(SWITCH, INPUT_PULLUP);
-  lastState = digitalRead(SWITCH);
-  lastStateTimestamp = millis();
+  gLastState = digitalRead(SWITCH);
+  gLastStateTimestamp = millis();
   delay(100);
   attachInterrupt(digitalPinToInterrupt(SWITCH), onLockStateChange, CHANGE);
 
   digitalWrite(GREEN, HIGH);
 
-  if (!espActive)
+  if (!ESP_ACTIVE)
     return; // bail to loop
   
   // setup serial with esp-01

void onLockStateChange() {
  long now = millis();
  int state = digitalRead(SWITCH);
  if (state != lastState && now - lastStateTimestamp > 50) {
    lastStateTimestamp = millis();
    lastState = state;
    if (lastState == LOW) {
      sendLock();
    } else {
      sendUnlock();

  if (!sendATJoinNetwork()) blinkLEDForever();
  blink(BLINK_COUNT, BLINK_DURATION, 1, 1, 1);
}
void loop() {
  if (gLastState == LOW) {
    gCount++;
  } else if (gCount > 0) { 
      gCount -= gCourtesyDelay;
      digitalWrite(RED, LOW);
      digitalWrite(YELLOW, HIGH);
      digitalWrite(GREEN, LOW);
  } else {
      gCount = 0;
      digitalWrite(RED, LOW);
      digitalWrite(YELLOW, LOW);
      digitalWrite(GREEN, HIGH);
