           callback null, machine
 
 
-  generateSlugFromLabel = ({user, group, label, index}, callback)->
-
-    slug = if index? then "#{label}-#{index}" else label
-    slug = slugify slug
-
-    JMachine.count {
-      users : $elemMatch: id: user.getId()
-      groups: $elemMatch: id: group.getId()
-      slug
-    }, (err, count)->
-
-      return callback err  if err?
-
-      if count is 0
-        callback null, slug
+  # Instance Methods
+
+  addUsers: (usersToAdd, owner, callback)->
+
+    users = @users.splice 0
+
+    for user in usersToAdd
+      users = addUser users, user, owner
+
+    @update $set: { users }, callback
+
+
+  removeUsers: (usersToRemove, callback)->
+
+    users = @users.splice 0
+
+    for user in usersToRemove
+      users = removeUser users, user
+
+    @update $set: { users }, callback
+
+
+  shareWith: (options, callback)->
+
+    { target, user, owner } = options
+    user  ?= yes
+    owner ?= no
+
+    unless target?
+      return callback new KodingError "Target required."
+
+    JUser = require '../user'
+    JName = require '../name'
+
+    JName.fetchModels target, (err, result)=>
+
+      if err or not result?
+        return callback new KodingError "Target not found."
+
+      targets = (target.models[0]  for target in result)
+
+      [ target ] = targets
+
+      if target instanceof JUser
+
+        if user
+        then @addUsers targets, owner, callback
+        else @removeUsers targets, callback
+
       else
-        index ?= 0
-        index += 1
-        generateSlugFromLabel {user, group, label, index}, callback
-
-
-
-  @one$: permit 'list machines',
+        callback new KodingError "Target does not support machines."
+
+
+
+  # Shared Methods
+  # --------------
+
+  # Static Methods
+
+  @one$ = permit 'list machines',
 
     success: revive
 

        assignedAt      : Date


  @create = (data, callback)->

    # JMachine.uid is a unique id which is generated from:

        @update $set: { label }, (err)-> kallback err, slug


  # .share can be used like this:
  #
  # JMachineInstance.shareWith { user: yes, owner: no, target: "gokmen"}, cb
