      strncpy(newSwitch->group, payload, 5);
      newSwitch->group[5] = '\0';
      
-     if (firstSwitch == NULL && lastSwitch == NULL) {
+     if (firstSwitch == NULL) {
        firstSwitch = newSwitch;
      } else {
-       lastSwitch->next = newSwitch; 
+       Ws *last = firstSwitch;
+       while(last->next != NULL) {
+         last = last->next;  
+       }
+   
+       last->next = newSwitch; 
      }
-     lastSwitch = newSwitch;
 
      
      char topic[53+1];

   //Serial.println(payload); 
   
   // Strip /sys/158293-433MhzBridge/devices/Switch- from string to obtain switch number   
   int switchNumber;
   sscanf(topic+sizeof(CLIENT_ID)/sizeof(char)+5+15, "%d", &switchNumber);
   if (switchNumber > 99) {
      return; 
   }

void setWifi(Ws* s, char* state);
void addWifiSwitch(char* topic, char* payload);
void listSwitches();
int switchNumberFromTopic(char* topic);
void connectToMqttServer();

Ws* findSwitch(int id);

// Settings 
