 
 void stateWorking()
 {
-  
+
   writeTempAndHumToLcd();
 
-  if (!hatchOpen && (tempSensorValue >= alertLevel ||( humSensorValue >= humLevel && tempSensorValue >= 20))){
-    //Serial.print("Alert! over ");
-    //Serial.print(alertLevel);
-    //Serial.print("degrees, open hatch\n");
+  if (!hatchOpen && (tempSensorValue >= alertLevel || ( humSensorValue >= humLevel && tempSensorValue >= 20))) {
+    LOG_DEBUG2("Alert! over ");
+    LOG_DEBUG2(alertLevel);
+    LOG_DEBUG2("degrees, open hatch\n");
     turnServo(90);
-    hatchOpen=true;
-  }
-  if (hatchOpen && ((tempSensorValue <= alertLevel-2 && humSensorValue <= humLevel) || tempSensorValue <= 20)){
-    //Serial.print("Alert! less than ");
-    //Serial.print(alertLevel);
-    //Serial.print("(");
-    //Serial.print(tempSensorValue);
-    //Serial.print(") degrees, close hatch\n");
+    hatchOpen = true;
+  }
+  if (hatchOpen && ((tempSensorValue <= (alertLevel - 2) && humSensorValue <= (humLevel-2)) || tempSensorValue <= 20)) {
+    LOG_DEBUG2("Alert! less than ");
+    LOG_DEBUG2(alertLevel);
+    LOG_DEBUG2("(");
+    LOG_DEBUG2(tempSensorValue);
+    LOG_DEBUG2(") degrees, close hatch\n");
     turnServo(180);
-    hatchOpen=false;
-  }  
+    hatchOpen = false;
+  }
 }
 
 void writeTempAndHumToLcd() {
-  lcd.setCursor(0,0);
-  int temp = (int)tempSensorValue;
-  lcd.print(temp);
+  char float_str[10] = {0};
+  lcd.setCursor(0, 0);
+  dtostrf(tempSensorValue, 4, 1, float_str);
+  lcd.print(float_str);
   lcd.write(B11011111); // Degree symbol
   lcd.print("C ");
-  lcd.print("HUM=");
-  lcd.print(humSensorValue);
+  memset(&float_str, 0, sizeof(float_str));
+  dtostrf(humSensorValue, 3, 1, float_str);
+  lcd.print("H=");
+  lcd.print(float_str);
   lcd.print("\%");
-  
-  if (temp>maxC) {
-    maxC=temp;
-  }
-  if (temp<minC) {
-    minC=temp;
-  }
-  lcd.setCursor(0,1);
-  lcd.print("H=");
+
+  if ((int)tempSensorValue > maxC ||
+      ((int)tempSensorValue < maxC && maxC == 125 && (int)tempSensorValue != 0 )) {
+    maxC = (int)tempSensorValue;
+  }
+  if ((int)tempSensorValue < minC && minC != -125 ||
+      ((int)tempSensorValue > minC && minC == -125 && (int)tempSensorValue != 0 )) {
+    minC = (int)tempSensorValue;
+  }
+  lcd.setCursor(0, 1);
+  lcd.print("Hi=");
   lcd.print(maxC);
   lcd.write(B11011111);
-  lcd.print("C L=");
+  lcd.print("C Lo=");
   lcd.print(minC);
   lcd.write(B11011111);
   lcd.print("C ");

      humLevel = humLimitPotValue;
    }
  }
  
  if (state == STATE_SETUP){
    stateSetup();  
  }
  if (state == STATE_WORKING||state == STATE_INITIAL){
    stateWorking();
  }
}

void readValues()
{
    switch (sensor.read()) {
    case Dht11::OK:
      humSensorValue = sensor.getHumidity();
      tempSensorValue = sensor.getTemperature();
      //Serial.print("\nTemperature (C): ");
      //Serial.print(tempSensorValue);
      //Serial.print("\nHumidity (%): ");
      //Serial.print(humSensorValue);
      //Serial.println();
      break;
    case Dht11::ERROR_CHECKSUM:
      Serial.println("Checksum error");
      break;
    case Dht11::ERROR_TIMEOUT:
      Serial.println("Timeout error");
     break;
    default:
      Serial.println("Unknown error");
      break;
  }

  delay(10);
  tempLimitPotValue = analogRead(tempPotPin); // Read the pot value
  delay(10);
  tempLimitPotValue = analogRead(tempPotPin); // Read the pot value
  tempLimitPotValue = map(tempLimitPotValue, 0, 1023, 20, 40); // Map the values from 20 to 40 degrees
  //Serial.print("tp:");
  //Serial.println(tempLimitPotValue);

  delay(10);
  humLimitPotValue = analogRead(humPotPin); // Read the pot value
  delay(10);
  humLimitPotValue = analogRead(humPotPin); // Read the pot value
  humLimitPotValue = map(humLimitPotValue, 0, 1023, 20, 100); // Map the values from 20 to 100%
  //Serial.print("hp:");
  //Serial.println(humLimitPotValue);

  buttonState = digitalRead(buttonPin); // Check for button press  
}

void turnServo(uint16_t degree)
{
  servo1.attach(servo1Pin); // Attaches the servo on pin 14 to the servo1 object
  servo1.write(degree);  // Put servo1 at home position
  delay(3000);
  servo1.detach();  //detach not to disturb SoftwareSerial

void handleState()
{
  if (buttonState == HIGH) { // Change scale state if pressed
    LOG_DEBUG("button pressed, state is");
    LOG_DEBUGLN(state);
    if (state == STATE_INITIAL || state == STATE_WORKING) {
      state = STATE_SETUP;
      lcd.setLED2Pin(LOW);
      lcd.setLED1Pin(LOW);
