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


        }
        var once = false
        s.onDisconnect = {[unowned self] (error: NSError?) in
            if !once {
                once = true
                self.runTest(caseNum)
            }
            self.removeSocket(s)
        }
        s.connect()
    }

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