   static unsigned long redTime = 0;
   int packetSize;
   int i;
-  static int adc[6] = {
-    0,0,0,0,0,0  };
+  static int adc[6] = {0,0,0,0,0,0};
   static char chan = 0;
   float temp;
   static unsigned long muxTime = 0;
   char tempString[40];
 
-  switch(s) {
-
-  case 0:   //wait for first packet
-    packetSize = Udp.parsePacket();
-    if (packetSize) {
-      if (!createDataFile()) {
+  switch(s)
+  {
+
+    case 0:   //wait for first packet
+      packetSize = Udp.parsePacket();
+      if (packetSize)
+      {
+        if (!createDataFile())
+        {
+          i = Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
+          initialTime = millis();
+          packetTime = initialTime;
+          writeTime = 0;
+          if (packetBuffer[0] != '#')
+          {
+            dataFile.print(";\r\n");
+            dataFile.print(writeTime);
+            sprintf(tempString, ";%d;%d;%d;%d;%d;%d;", adc[0], adc[1], adc[2], adc[3], adc[4], adc[5]);
+            dataFile.print(tempString);
+          }
+          else
+          {
+            dataFile.print(";");
+          }
+          dataFile.write((uint8_t *)packetBuffer, i);
+          dataFile.flush();
+          redTime = initialTime + errorFlash;
+          digitalWrite(redPin, HIGH);
+          digitalWrite(redPin2, HIGH);
+          s = 1;
+        }
+        else
+        {
+          s = 7;
+        }
+      } // if
+      break;
+
+    case 1:   // wait for packet
+      packetSize = Udp.parsePacket();
+      if (packetSize)
+      {
         i = Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
-        initialTime = millis();
-        packetTime = initialTime;
-        writeTime = 0;
-        if (packetBuffer[0] != '#') {
+        packetTime = millis();
+        writeTime = packetTime - initialTime;
+        if (packetBuffer[0] != '#')
+        {
           dataFile.print(";\r\n");
           dataFile.print(writeTime);
           sprintf(tempString, ";%d;%d;%d;%d;%d;%d;", adc[0], adc[1], adc[2], adc[3], adc[4], adc[5]);
           dataFile.print(tempString);
         }
         else
+        {
           dataFile.print(";");
+        }
         dataFile.write((uint8_t *)packetBuffer, i);
         dataFile.flush();
-        redTime = initialTime + errorFlash;
+        redTime = packetTime + errorFlash;
         digitalWrite(redPin, HIGH);
         digitalWrite(redPin2, HIGH);
-        s = 1;
-      }
-      else
-        s = 7;
-    } // if
-    break;
-
-  case 1:   // wait for packet
-    packetSize = Udp.parsePacket();
-    if (packetSize) {
-      i = Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
-      packetTime = millis();
-      writeTime = packetTime - initialTime;
-      if (packetBuffer[0] != '#') {
-        dataFile.print(";\r\n");
-        dataFile.print(writeTime);
-        sprintf(tempString, ";%d;%d;%d;%d;%d;%d;", adc[0], adc[1], adc[2], adc[3], adc[4], adc[5]);
-        dataFile.print(tempString);
-      }
-      else
-        dataFile.print(";");
-      dataFile.write((uint8_t *)packetBuffer, i);
-      dataFile.flush();
-      redTime = packetTime + errorFlash;
-      digitalWrite(redPin, HIGH);
-      digitalWrite(redPin2, HIGH);
-    }
-    if ((millis() - packetTime) > timeOut)
-      s = 3;
-    break;
-
-  case 3:  // close
-    dataFile.print("\r\n");
-    dataFile.close();
-    s = 0;
-    break;
-
-  case 7:   // error
-    break;
+      }
+      if ((millis() - packetTime) > timeOut)
+      {
+        s = 3;
+      }
+      break;
+
+    case 3:  // close
+      dataFile.print("\r\n");
+      dataFile.close();
+      s = 0;
+      break;
+
+    case 7:   // error
+      break;
 
   }  // switch s
 
 
   //led state machine
 
-  switch(ledState) {
-  case 0:
-    if (millis() > redTime) {
-      digitalWrite(redPin, LOW);
-      digitalWrite(redPin2, LOW);
-    }
-    if ( millis() > grnTime) {
-      digitalWrite(grnPin, HIGH);
-      digitalWrite(grnPin2, HIGH);
-      grnTime = millis() + shortOn;
-      ledState = 1;
-    }
-    break;
-
-  case 1:
-    if (millis() > redTime) {
-      digitalWrite(redPin, LOW);
-      digitalWrite(redPin2, LOW);
-    }
-    if (millis() > grnTime) {
-      digitalWrite(grnPin, LOW);
-      digitalWrite(grnPin2, LOW);
-      grnTime = millis() + shortOff;
-      if (s == 0)
+  switch(ledState)
+  {
+    case 0:
+      if (millis() > redTime)
+      {
+        digitalWrite(redPin, LOW);
+        digitalWrite(redPin2, LOW);
+      }
+      if ( millis() > grnTime)
+      {
+        digitalWrite(grnPin, HIGH);
+        digitalWrite(grnPin2, HIGH);
+        grnTime = millis() + shortOn;
+        ledState = 1;
+      }
+      break;
+
+    case 1:
+      if (millis() > redTime)
+      {
+        digitalWrite(redPin, LOW);
+        digitalWrite(redPin2, LOW);
+      }
+      if (millis() > grnTime)
+      {
+        digitalWrite(grnPin, LOW);
+        digitalWrite(grnPin2, LOW);
+        grnTime = millis() + shortOff;
+        if (s == 0)
+        {
+          ledState = 3;
+        }
+        else
+        {
+          ledState = 2;
+        }
+      }
+      break;
+
+    case 2:
+      if (millis() > redTime)
+      {
+        digitalWrite(redPin, LOW);
+        digitalWrite(redPin2, LOW);
+      }
+      if ( millis() > grnTime)
+      {
+        digitalWrite(grnPin, HIGH);
+        digitalWrite(grnPin2, HIGH);
+        grnTime = millis() + shortOn;
         ledState = 3;
-      else
-        ledState = 2;
-    }
-    break;
-
-  case 2:
-    if (millis() > redTime) {
-      digitalWrite(redPin, LOW);
-      digitalWrite(redPin2, LOW);
-    }
-    if ( millis() > grnTime) {
-      digitalWrite(grnPin, HIGH);
-      digitalWrite(grnPin2, HIGH);
-      grnTime = millis() + shortOn;
-      ledState = 3;
-    }
-    break;
-
-  case 3:
-    if (millis() > redTime) {
-      digitalWrite(redPin, LOW);
-      digitalWrite(redPin2, LOW);
-    }
-    if (millis() > grnTime) {
-      digitalWrite(grnPin, LOW);
-      digitalWrite(grnPin2, LOW);
-      grnTime = millis() + longOff;
-      if (s == 7)
-        ledState = 4;
-      else
-        ledState = 0;
-    }
-    break;
-
-  case 4:
-    if (millis() > grnTime) {
-      grnTime = millis() + shortOff;
-      digitalWrite(grnPin, HIGH);
-      digitalWrite(grnPin2, HIGH);
-      digitalWrite(redPin, LOW);
-      digitalWrite(redPin2, LOW);
-      ledState = 5;
-    }
-    break;
-
-  case 5:
-    if (millis() > grnTime) {
-      grnTime = millis() + shortOff;
-      digitalWrite(grnPin, LOW);
-      digitalWrite(grnPin2, LOW);
-      digitalWrite(redPin, HIGH);
-      digitalWrite(redPin2, HIGH);
-      if (s == 7)
-        ledState = 4;
-      else
-        ledState = 3;
-    }
-    break;   
-  }  // led switch
-
-  if (millis() > muxTime) {
+      }
+      break;
+
+    case 3:
+      if (millis() > redTime)
+      {
+        digitalWrite(redPin, LOW);
+        digitalWrite(redPin2, LOW);
+      }
+      if (millis() > grnTime)
+      {
+        digitalWrite(grnPin, LOW);
+        digitalWrite(grnPin2, LOW);
+        grnTime = millis() + longOff;
+        if (s == 7)
+        {
+          ledState = 4;
+        }
+        else
+        {
+          ledState = 0;
+        }
+      }
+      break;
+
+    case 4:
+      if (millis() > grnTime)
+      {
+        grnTime = millis() + shortOff;
+        digitalWrite(grnPin, HIGH);
+        digitalWrite(grnPin2, HIGH);
+        digitalWrite(redPin, LOW);
+        digitalWrite(redPin2, LOW);
+        ledState = 5;
+      }
+      break;
+
+    case 5:
+      if (millis() > grnTime)
+      {
+        grnTime = millis() + shortOff;
+        digitalWrite(grnPin, LOW);
+        digitalWrite(grnPin2, LOW);
+        digitalWrite(redPin, HIGH);
+        digitalWrite(redPin2, HIGH);
+        if (s == 7)
+        {
+          ledState = 4;
+        }
+        else
+        {
+          ledState = 3;
+        }
+      }
+      break;   
+    }  // led switch
+
+  if (millis() > muxTime)
+  {
     temp = (float)analogRead(0) * 0.488;
     adc[chan] = (int)temp;
     //Serial.println(adc[chan]);
-    if (++chan > 5) chan = 0;
+    if (++chan > 5) 
+    {
+      chan = 0;
+    }
     mux(chan);
     muxTime = millis() + 50;
   }

  sprintf(buffer, "%02d", minute);
  Serial.print(buffer);
  Serial.println(AMPM);
}


// --------------------------------------------------
//   read the time from the RTC
// --------------------------------------------------
void readTime() {
  Wire.beginTransmission(DS1307);
  Wire.write(byte(0));
  Wire.endTransmission();

// --------------------------------------------------
//   blink error lights
// --------------------------------------------------
void error()
{
  while(1)
  {
    digitalWrite(redPin, LOW);
    delay(shortOff);
    digitalWrite(redPin, HIGH);
