     
     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

  
  func writePassword(password: [UInt8], additionalKeys: [UInt8]? = nil, handler: CompletionHandler) {
    tokenCommander.keystrokesPassword(password, additionalKeys: additionalKeys, handler: handler)
  }
  
  

    tokenPeripheral.writeValue(data, forCharacteristic: tokenWriteCharacteristic, type: type);
  }
  
  private func async(handler: () -> (Void)) {
    dispatch_async(dispatch_get_main_queue(), handler)
  }
  
}