       #endif
       
       // parse from the beginning until I find a M, D, L, S, A, P, B, U, G, T
-      int buffer_length = strlen(current_buffer);
-      for (int i = 0; i < buffer_length; i++)
+      int current_buffer_length = strlen(current_buffer);
+      for (int i = 0; i < current_buffer_length; i++)
         if ((current_buffer[i] >= 'A' && current_buffer[i] <= 'Z') || (current_buffer[i] >= 'a' && current_buffer[i] <= 'z')){// a command
           // find the terminal character #
-          int j = i + 1;
-          for (; j < buffer_length && current_buffer[j] != '#'; j++);// parse until I find the termination char
-          if (j < buffer_length){
+          int j = current_buffer_length - 1;
+          for (; j > i && current_buffer[j] != '#'; j--);// parse (from the end) until I find the termination char
+          if (j > i){
 
               #ifdef DEBUG
                 char tmp_str[64];

    }
    serial_buffer[num_read] = 0;// terminate the string
    if (serial_buffer[0] || current_buffer[0]){
      strcat(current_buffer, serial_buffer);
      
      #ifdef DEBUG
        Serial.write("initial buffer is=");

           sprintf(serial_out, "T#");
           i += 2;
         }
         if (tmp_str[i] == 'V' || tmp_str[i] == 'v'){// test connection
           sprintf(serial_out, "%s#", firmware_version);
           i += 2;
         }
    }
    else
      i++;
