diff --git a/templates/devices.html b/templates/devices.html
index a109c79..c05ea72 100644
--- a/templates/devices.html
+++ b/templates/devices.html
@@ -80,8 +80,8 @@
 <!-- Overlay dla masowej aktualizacji systemu (5 minut) -->
 <div id="mass-system-update-overlay" style="display:none; position:fixed; top:0; left:0; width:100%; height:100%; background:rgba(0,0,0,0.7); z-index:1000; color:white; text-align:center; padding-top:200px;">
   <h3>Masowa aktualizacja systemu rozpoczęta...</h3>
-  <div style="width:50%; margin: 20px auto; background:#444; border-radius:5px;">
-    <div id="mass-system-progress" style="width:0%; height:30px; background:#4caf50; border-radius:5px;"></div>
+  <div class="progress-container">
+    <div id="mass-system-progress" class="progress-bar"></div>
   </div>
   <p id="mass-system-timer">300 sekund</p>
 </div>
@@ -89,8 +89,8 @@
 <!-- Overlay dla masowej aktualizacji firmware (2 minuty) -->
 <div id="mass-firmware-update-overlay" style="display:none; position:fixed; top:0; left:0; width:100%; height:100%; background:rgba(0,0,0,0.7); z-index:1000; color:white; text-align:center; padding-top:200px;">
   <h3>Masowa aktualizacja firmware (reboot) rozpoczęta...</h3>
-  <div style="width:50%; margin: 20px auto; background:#444; border-radius:5px;">
-    <div id="mass-firmware-progress" style="width:0%; height:30px; background:#4caf50; border-radius:5px;"></div>
+  <div class="progress-container">
+    <div id="mass-firmware-progress" class="progress-bar"></div>
   </div>
   <p id="mass-firmware-timer">120 sekund</p>
 </div>
@@ -104,12 +104,20 @@
 </div>
 
 <script>
-  // Funkcja "Select all" – zaznacza lub odznacza wszystkie checkboxy
-  document.getElementById('select-all').addEventListener('change', function() {
-    var checkboxes = document.querySelectorAll('input[name="selected_devices"]');
-    for (var checkbox of checkboxes) {
-      checkbox.checked = this.checked;
-    }
+  // Dodajemy event listenery raz, aby uniknąć wielokrotnego przypisywania
+  document.addEventListener('DOMContentLoaded', function() {
+    document.getElementById('select-all').addEventListener('change', function() {
+      var checkboxes = document.querySelectorAll('input[name="selected_devices"]');
+      for (var checkbox of checkboxes) {
+        checkbox.checked = this.checked;
+      }
+    });
+    
+    document.getElementById('mass-firmware-reboot-btn').addEventListener('click', onMassFirmwareReboot);
+    document.getElementById('mass-firmware-cancel-btn').addEventListener('click', function() {
+      alert("Restart został anulowany. Pamiętaj, że firmware update wymaga rebootu.");
+      document.getElementById('mass-firmware-reboot-prompt').style.display = 'none';
+    });
   });
 
   // Pobierz zaznaczone urządzenia
@@ -131,7 +139,7 @@
     }
     // Wysyłamy update systemu dla każdego urządzenia asynchronicznie
     selectedDevices.forEach(function(id) {
-      fetch("{{ url_for('update_device', device_id=0) }}".replace("0", id), { method: 'POST' })
+      fetch(`/device/${id}/update`, { method: 'POST' })
         .catch(function(error){ console.error('Błąd aktualizacji systemu dla urządzenia ' + id, error); });
     });
     // Pokaż overlay z paskiem postępu (5 minut)
@@ -149,7 +157,7 @@
         clearInterval(interval);
         // Po zakończeniu odliczania, dla każdego urządzenia wykonaj force_check
         selectedDevices.forEach(function(id) {
-          fetch("{{ url_for('force_check', device_id=0) }}".replace("0", id), { method: 'GET' })
+          fetch(`/device/${id}/force_check`, { method: 'GET' })
             .catch(function(error){ console.error('Błąd force check dla urządzenia ' + id, error); });
         });
         location.reload();
@@ -166,52 +174,59 @@
     }
     // Wysyłamy update firmware dla każdego urządzenia asynchronicznie
     selectedDevices.forEach(function(id) {
-      fetch("{{ url_for('update_firmware', device_id=0) }}".replace("0", id), { method: 'POST' })
+      fetch(`/device/${id}/update_firmware`, { method: 'POST' })
         .catch(function(error){ console.error('Błąd aktualizacji firmware dla urządzenia ' + id, error); });
     });
-    // Zamiast confirm() wyświetlamy dynamiczny prompt
-    var promptDiv = document.getElementById('mass-firmware-reboot-prompt');
-    promptDiv.style.display = 'block';
-
-    // Obsługa przycisku restartu w prompt
-    document.getElementById('mass-firmware-reboot-btn').addEventListener('click', function() {
-      promptDiv.style.display = 'none';
-
-    // Wysyłamy reboot dla każdego wybranego urządzenia
-      selectedDevices.forEach(function(id) {
-        fetch("{{ url_for('restart_device', device_id=0) }}".replace("0", id), { method: 'POST' })
-          .catch(function(error){ console.error('Błąd wysyłania reboot dla urządzenia ' + id, error); });
-      });
-
-      // Pokaż overlay z paskiem postępu dla reboot (2 minuty)
-      var overlay = document.getElementById('mass-firmware-update-overlay');
-      overlay.style.display = 'block';
-      var timeLeft = 120; // 120 sekund
-      var progressBar = document.getElementById('mass-firmware-progress');
-      var timerDisplay = document.getElementById('mass-firmware-timer');
-      var interval = setInterval(function(){
-        timeLeft--;
-        var percent = ((120 - timeLeft) / 120) * 100;
-        progressBar.style.width = percent + '%';
-        timerDisplay.textContent = timeLeft + ' sekund';
-        if(timeLeft <= 0){
-          clearInterval(interval);
-          // Po zakończeniu odliczania, dla każdego urządzenia wykonaj force_check
-          selectedDevices.forEach(function(id) {
-            fetch("{{ url_for('force_check', device_id=0) }}".replace("0", id), { method: 'GET' })
-              .catch(function(error){ console.error('Błąd force check dla urządzenia ' + id, error); });
-          });
-          location.reload();
-        }
-      }, 1000);
-    });
-
-    // Obsługa przycisku anulowania restartu w prompt
-    document.getElementById('mass-firmware-cancel-btn').addEventListener('click', function() {
-      alert("Restart został anulowany. Pamiętaj, że firmware update wymaga rebootu.");
-      promptDiv.style.display = 'none';
-    });
+    // Wyświetlamy dynamiczny prompt restartu
+    document.getElementById('mass-firmware-reboot-prompt').style.display = 'block';
   });
+
+  // Funkcja sekwencyjnego wysyłania reboot (z opóźnieniem)
+  function sendRebootSequentially(devices, index = 0) {
+    if (index >= devices.length) return Promise.resolve();
+    return fetch(`/device/${devices[index]}/restart`, { method: 'POST' })
+      .catch(function(error) {
+        console.error('Błąd wysyłania reboot dla urządzenia ' + devices[index], error);
+      })
+      .then(function() {
+        // Opóźnienie 500 ms przed kolejnym rebootem
+        return new Promise(resolve => setTimeout(resolve, 500));
+      })
+      .then(function() {
+        return sendRebootSequentially(devices, index + 1);
+      });
+  }
+
+  // Obsługa przycisku restartu w prompt dla masowego firmware update
+  function onMassFirmwareReboot() {
+    document.getElementById('mass-firmware-reboot-prompt').style.display = 'none';
+    var selectedDevices = getSelectedDeviceIds();
+    // Wysyłamy rebooty sekwencyjnie
+    sendRebootSequentially(selectedDevices)
+      .then(function() {
+        // Po wysłaniu reboot dla wszystkich urządzeń, pokazujemy overlay z 2-minutowym paskiem postępu
+        var overlay = document.getElementById('mass-firmware-update-overlay');
+        overlay.style.display = 'block';
+        var timeLeft = 120; // 120 sekund
+        var progressBar = document.getElementById('mass-firmware-progress');
+        var timerDisplay = document.getElementById('mass-firmware-timer');
+        var interval = setInterval(function(){
+          timeLeft--;
+          var percent = ((120 - timeLeft) / 120) * 100;
+          progressBar.style.width = percent + '%';
+          timerDisplay.textContent = timeLeft + ' sekund';
+          if(timeLeft <= 0){
+            clearInterval(interval);
+            // Po zakończeniu odliczania, dla każdego urządzenia wykonaj force_check
+            selectedDevices.forEach(function(id) {
+              fetch(`/device/${id}/force_check`, { method: 'GET' })
+                .catch(function(error){ console.error('Błąd force check dla urządzenia ' + id, error); });
+            });
+            location.reload();
+          }
+        }, 1000);
+      });
+  }
   
   // Obsługa standardowego przycisku "Odśwież wybrane"
   document.getElementById('mass-update-form').addEventListener('submit', function(e) {
@@ -222,7 +237,7 @@
       return;
     }
     selectedDevices.forEach(function(id) {
-      fetch("{{ url_for('force_check', device_id=0) }}".replace("0", id), { method: 'GET' })
+      fetch(`/device/${id}/force_check`, { method: 'GET' })
         .catch(function(error){ console.error('Błąd force check dla urządzenia ' + id, error); });
     });
     setTimeout(function(){ location.reload(); }, 2000);