     if(timeStatus()!= timeSet) {
         // CLK error
         char error[] = "clock error" ;
-		char line2[]= "***" ;
-        Serial.println(error);
-		lcd_print(error,line2);	
-        for(;;);
+        display_output(error);
+        while (1) ;
     }
 
     // initialize SD card
     pinMode(SS, OUTPUT);
     if (!SD.begin(chipSelect)) {
-        Serial.println("Card failed, or not present");
+        char error[] = "Card failed, or not present";
+        display_output(error);
         // don't do anything more:
         while (1) ;
     }
     
-	// LCD
-	
     Alarm.timerRepeat(10, log_data);
 
 }
 
-void lcd_print(char* line1, char* line2) {
+void display_output(char* buffer) {
+    #if defined(SERIAL_DEBUG)
+        Serial.println(buffer);
+    #endif
 
     pinMode(LCD_PIN, OUTPUT);
     digitalWrite(LCD_PIN, HIGH);
     lcd.begin(16,2);       
     lcd.clear();
-    // line1
+
+    // first line
     lcd.setCursor(0,0);
-    lcd.print(line1); 
-    lcd.setCursor(0,1);
-    lcd.print(line2); 
+    int i = 0 ;
+    while( i < 16 && (buffer[i] != '\0')) {
+        lcd.print(buffer[i]) ;
+        i++ ;
+    }
+    
+    if(i == 15) {
+        while( i < 16 && (buffer[i] != '\0')) {
+            lcd.print(buffer[i]) ;
+            i++ ;
+        }
+    }
+
 }
+
 
 void log_data() {
 
     char ts[18] ;
-	char data[12] ;
-	get_sensor_data(ts,data);
-
-    dataFile = SD.open("yuktix.log", O_CREAT | O_WRITE | O_APPEND);
-    if (! dataFile) {
-      Serial.println("error opening yuktix.log");
-      // Wait forever since we cant write data
-      while (1) ;
-    }
-
-    // write to SD card
-    dataFile.print(ts);
-    dataFile.print(",");
-    dataFile.println(data);
-	micro_delay(20);
-    dataFile.close();  
-    micro_delay(20);
-
-    int hh = hour();
-    int mm = minute();
-	char line2[6] ;
-	sprintf(line2,"%02d:%02d",hh,mm);
-	
-	lcd_print(line2,data);
-
-}
-
-void get_sensor_data(char* ts, char* data) {
 
     // timestamp
     int hh = hour();

    sprintf(ts,"%02d-%02d-%02d %02d:%02d:%02d",yyyy,mt,dd,hh,mm,ss);
	ts[17] = '\0' ;	

	// sensors
    int dht11_code = DHT11.read(DHT11_PIN);
    micro_delay(200);
	int ldr = analogRead(LDR_PIN); 
	
    if(dht11_code != 0 ) {
        // error
        sprintf(data,"%11s","TH_ERR");

    } else {
		// 11 char wide data
        sprintf(data,"%-03d,%-02d,%-04d",DHT11.temperature,DHT11.humidity,ldr);
    }

    data[11] = '\0' ;
}

// param n is to ensure n*10 ms delay
void micro_delay(int n) {
    for(int i = 0 ; i < n ; i++) {
        delayMicroseconds(10000);
        // pat watchdog every 100*10 ms
        // if((i > 100) && (i %100 == 0 )) wdt_reset();
    }
}



// @change pins
#define DHT11_PIN 2 
#define SERIAL_DEBUG 1

int LCD_PIN = 13;    
int LDR_PIN = A0 ;
