 //    }
     
     deinit {
+        print("Coulomb deinit")
         stopAdvertisingHost()
         stopSearchingForHosts()
         session.disconnect()
     }
     
+    func setUpSession() {
+        session = MCSession(peer: self.myPeerId, securityIdentity: nil, encryptionPreference: .Required)
+        session.delegate = self
+    }
     // MARK: Methods for host
     public func startAdvertisingHost() {
+        stopSearchingForHosts()
         self.host = myPeerId
-        if serviceAdvertiser == nil {
+        if self.serviceAdvertiser == nil {
             serviceAdvertiser = MCNearbyServiceAdvertiser(peer: myPeerId,
                                                           discoveryInfo: ["peerType": "host"], serviceType: serviceType)
-            serviceAdvertiser?.delegate = self
-        }
-        serviceAdvertiser?.startAdvertisingPeer()
+            self.serviceAdvertiser?.delegate = self
+        }
+        self.serviceAdvertiser?.startAdvertisingPeer()
     }
     
     public func stopAdvertisingHost() {
         serviceAdvertiser?.stopAdvertisingPeer()
+        serviceAdvertiser = nil
     }
     
     // MARK: Methods for guest
     public func startSearchingForHosts() {
+        stopAdvertisingHost()
         self.host = nil
         if serviceBrowser == nil {
             serviceBrowser = MCNearbyServiceBrowser(peer: myPeerId, serviceType: serviceType)

    
    public func stopSearchingForHosts() {
        serviceBrowser?.stopBrowsingForPeers()
    }
    
    public func connectToHost(host: MCPeerID, context: NSData? = nil, timeout: NSTimeInterval = defaultTimeout) {

            } else {
                DLog("%@", "not connected to \(session.hashValue)")
                // If self is disconnected or current host is disconnected
                print("passed in \(session.connectedPeers)")
                print("self: \(self.session.connectedPeers)")
                print(session == self.session)
//                session.disconnect()
                
                if self.host == peerID {
                    DLog("%@", "Host was removed")
                    
                    dispatch_sync(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0)) {
                        self.session.disconnect()
                    }
//                    browser(serviceBrowser!, lostPeer: peerID)
//                    setUpSession()
                    delegate?.disconnectedFromSession()
                }
            }
