       newData.sessionId = collaborator.sessionId
       participants.remove index
       participants.insert index, newData
-
-fetchParticipants = (channelId, callback) ->
-  {socialapi} = kd.singletons
-  socialapi.channel.listParticipants {channelId}, (err, participants) ->
-    return callback err  if err
-    idList = participants.map ({accountId}) -> accountId
-    query  = socialApiId: $in: idList
-
-    remote.api.JAccount.some query, {}
-      .then (accounts) -> callback null, accounts
-
-removeParticipantFromParticipantList = (references, nickname) ->
-  { participants } = references
+      break
+
+
+###*
+ * Removes a user with given nickname from manager's participants collection.
+ *
+ * @param {object} participants
+ * @param {string} nickname
+ * @api private
+###
+removeParticipantFromParticipantList = (participants, nickname) ->
+
   return console.warn 'participants is not set'  unless participants
 
-  for participant, index in participants.asArray()
-    if participant.nickname is nickname
-      participants.remove index
-      break
-
+  for p, index in participants.asArray() when p.nickname is nickname
+    participants.remove index
+    break
+
+
+###*
+ * Removes a user with given nickname from maps of RealtimeManager instance.
+ *
+ * @param {RealtimeManager} manager
+ * @param {string} nickname
+ * @api private
+###
 removeParticipantFromMaps = (manager, nickname) ->
+
   myWatchMapName = "#{nickname}WatchMap"
   mySnapshotName = "#{nickname}Snapshot"
 
   manager.delete 'map', myWatchMapName
   manager.delete 'map', mySnapshotName
 
-removeParticipantFromPermissions = (references, nickname) ->
-  references.permissions.delete nickname
-
+
+###*
+ * Removes a user with given nickname from
+ * participant map of RealtimeInstance.
+ *
+ * @param {object} permissions
+ * @param {string} nickname
+ * @api private
+###
+removeParticipantFromPermissions = (permissions, nickname) ->
+
+  permissions.delete nickname
+
+
+###*
+ * Removes user with given nickname from manager and references.
+ *
+ * @param {RealtimeManager} permissions
+ * @param {object} references - collections of collaboration.
+ * @param {string} nickname
+ * @api private
+###
 removeFromManager = (manager, references, nickname) ->
-  removeParticipantFromParticipantList references, nickname
+
+  removeParticipantFromParticipantList references.participants, nickname
   removeParticipantFromMaps manager, nickname
-  removeParticipantFromPermissions references, nickname
+  removeParticipantFromPermissions references.permissions, nickname
+
 
 module.exports = {
   loadCollaborationFile


  return { targetUser, targetIndex }

getReferences = (manager, channelId, initialSnapshot) ->
  nickname          = getNick()
  watchMapName      = "#{nickname}WatchMap"
  snapshotName      = "#{nickname}Snapshot"


  return refs


###*
 * Returns the collection from RealtimeManager instance with given name.
 * If collection is not created, this function will try to create a new
 * collection with given `defaultType` and `defaultValue` parameters.
 * If you are not gonna pass those values make sure that collection with the
 * given name is present.
 *
 * Example:
 *     # get collection syntax:
 *     participants = getFromManager rtm, 'participants'
 *     # get collection with default values in case that collection does not exist.
 *     participants = getFromManager rtm, 'participants', 'list', []
 *
 * @param {RealtimeManager} manager
 * @param {string} name
 * @param {string} defaultType - for now just 'list' and 'map'
 * @param {(object|Array)} - array for 'list', object for 'map'
 * @return {object} collection
###
getFromManager = (manager, name, defaultType, defaultValue) ->

  collection   = manager.getFromModel name
  collection or= manager.create defaultType, name, defaultValue

  return collection


###*
 * Updates logged in user's participant representation
 * from collaborators collection from RealtimeManager instance.
 *
 * @param {RealtimeManager} manager
 * @param {object} participants
###
registerCollaborationSessionId = (manager, participants) ->

  collaborators = manager.getCollaborators()
  for collaborator in collaborators when collaborator.isMe
    for user, index in participants.asArray() when user.nickname is getNick()
