 
     JGroup  = require './group'
     JUser   = require './user'
+
+    addVm = (target, user, {sudo, groups})->
+      vm = new JVM {
+        name: member.profile.nickname
+        users: [
+          { id: user.getId(), sudo: yes }
+        ]
+        groups: groups ? []
+      }
+      vm.save (err)-> target.addVm vm, handleError
+
+    wrapGroup =(group)-> [ { id: group.getId() } ]
 
     JUser.on 'UserCreated', (user)->
       console.warn 'User created hook needs to be implemented.'

      creator.fetchUser (err, user)->
        if err then handleError err
        else
          vm = new JVM {
            name: group.slug
            users: [
              { id: user.getId(), sudo: yes }
            ]
            groups: [
              { id: group.getId() }
            ]
          }
          vm.save (err)-> group.addVm vm, handleError

    JGroup.on 'GroupDestroyed', ({group, member})->
      group.fetchVms (err, vms)->

          JVM.update { groups: group.getId() }, { $pull: id: user.getId() }, handleError

    JGroup.on 'MemberRolesChanged', ({group, member})->
      return  if group.slug 'koding'
      member.fetchUser (err, user)->
        if err then handleError err
        else
