 Strophe.addConnectionPlugin 'caps', (->
 
   conn = null
+  dummyId = category: "client", type:"pc", name: "strophe", lang:""
 
   init = ( c ) ->
     conn = c
     Strophe.addNamespace 'CAPS', "http://jabber.org/protocol/caps"
     conn.disco.addFeature Strophe.NS.CAPS
     conn.disco.addFeature Strophe.NS.DISCO_INFO
-    conn.disco.addIdentity "client", "pc", "strophe", ""
 
-  addNode = (feature) -> conn.disco.addFeature feature
+  addFeature = (feature) -> conn.disco.addFeature feature
 
-  sendPres = -> conn.send $pres().c "c",
-    xmlns: Strophe.NS.CAPS
-    hash: "sha-1"
-    node: conn.disco._identities[0].name
-    ver: generateVerificationString()
+  removeFeature = (feature) -> conn.disco.removeFeature feature
+
+  sendPres = ->
+
+    if conn.disco._identities.length > 0
+      node = conn.disco._identities[0].name || ""
+    else
+      node = dummyId.name
+
+    conn.send $pres().c "c",
+      xmlns: Strophe.NS.CAPS
+      hash: "sha-1"
+      node: node
+      ver: generateVerificationString()
+
+  propertySort = (array, property) ->
+    array.sort (a,b) ->
+      if (a[property] > b[property]) then -1 else 1
 
   generateVerificationString = ->
+
+    ## Prepare
+
+    # copy the original identities
+    ids = []
+    ids.push(i) for i in conn.disco._identities
+
+    # copy the original features
+    features = []
+    features.push(k) for k in conn.disco._features
+
+    # chek if there are identities
+    if ids.length is 0 then ids.push dummyId
+
+    ## Generate string
 
     # 1. Initialize an empty string S.
 

    "#{b64_sha1 S}="

  # Public API
  
  init: init
  addNode: addNode
  sendPres: sendPres
  generateVerificationString: generateVerificationString


    # 7. For each extended service discovery information form:

    #  a) Append the XML character data of the FORM_TYPE field's <value/> element,
    #     followed by the '<' character.

    # not implemented yet

