     
     if let material = keyMaterial {
       self.keyMaterial = material
-    } else {
-      self.keyMaterial = KeyMaterial()
-    }
-    
-    self.tokenCommander = TokenCommander(keyMaterial: self.keyMaterial, protocolImpl: tokenPeriperalProtocolImpl)
-  }
+      self.tokenCommander = TokenCommander(keyMaterial: self.keyMaterial!, protocolImpl: tokenPeriperalProtocolImpl)
+    }
+  }
+  
+  func setKeyMaterial(keyMaterial: KeyMaterial) {
+    self.keyMaterial = keyMaterial
+    self.tokenCommander = TokenCommander(keyMaterial: self.keyMaterial!, protocolImpl: tokenPeriperalProtocolImpl)
+  }
+  
   
   func connect(hanlder: CompletionHandler) {
     self.tokenPeriperalProtocolImpl.connectionHandler = self.connectHandlerHook

    }

    send(cmd) { (reponse, error) in
      if let _ = error {
        handler(error)
      } else {
        handler(nil)
      }
    }
  }

  
  
  func send(cmd: Command, handler: ResponseHandler) {

          wCtx.isAck = false;
        } else {
          print("No ack for write");
          async { self.handler!(Response(), error: createError("Protocol", description: "Error during communication")) }
          break;
        }
      }
