         
         let s = WebSocket(url: URL(string: "ws://\(host)/getCaseCount")!, protocols: [])
         socketArray.append(s)
-        s.onText = {[unowned self] (text: String) in
+        s.onText = { [weak self]  (text: String) in
             if let c = Int(text) {
                 print("number of cases is: \(c)")
-                self.caseCount = c
+                self?.caseCount = c
             }
         }
-        s.onDisconnect = {[unowned self] (error: NSError?) in
-            self.getTestInfo(1)
-            self.removeSocket(s)
+        s.onDisconnect = { [weak self, weak s]  (error: NSError?) in
+            self?.getTestInfo(1)
+            self?.removeSocket(s)
         }
         s.connect()
     }

        //getTestInfo(1)
    }
    
    func removeSocket(_ s: WebSocket) {
        socketArray = socketArray.filter{$0 != s}
    }
    

    func finishReports() {
        let s = createSocket("updateReports",0)
        self.socketArray.append(s)
        s.onDisconnect = { [weak self, weak s]  (error: NSError?) in
            print("finished all the tests!")
            self?.removeSocket(s)
        }
        s.connect()
    }
