     char key = keypad.getKey();
     if (key) {
       setState(PIN_ENTRY);
-      buffer = key;
+      buffer += key;
       updateDisplay();
     } else if (timeoutExpired()) {
       setState(LOCKED);

      }
    }
  } else if (state == WAIT_FOR_UNLOCK) {
    if (Serial.available() > 0) {
      byte incomingByte = Serial.read();
      if (incomingByte == '\n') {
        Serial.println(buffer);
        if (buffer == "ACK;") {
          setState(UNLOCKED);
        } else {
          setState(INVALID_PIN);
        }
      } else {
        buffer += (char)incomingByte;
        resetTimeout();
      }
    } else if (timeoutExpired()) {
      setState(LOCKED);
    }

long timeout_start = 0;
long timeout = 10000;

String serial_buffer = "";
String serial_unfinished_line = "";
String buffer = "";

void updateDisplay() {
  lcd.clear();
  if (state == LOCKED) {
    lcd.print("Hello Stranger! ");
    lcd.setCursor(0, 1);
    lcd.print(" Door is locked.");
  } else if (state == PIN_ENTRY) {
    lcd.print("Please enter PIN");
    lcd.setCursor(0, 1);
    for (int i = 0; i < buffer.length(); i++) {
      lcd.print("*");
    }
  } else if (state == WAIT_FOR_UNLOCK) {
    lcd.print("Waiting for     ");
    lcd.setCursor(0, 1);
    lcd.print("   confirmation ");
  } else if (state == INVALID_PIN) {
    lcd.print("Invalid PIN     ");
    lcd.setCursor(0, 1);
    lcd.print("Please try again");
  } else if (state == UNLOCKED) {
    lcd.print("Space is open   ");
    lcd.setCursor(0, 1);
    lcd.print("Press 0# to lock");
