     JGroup.on 'MemberAdded', ({group, member})->
       member.fetchUser (err, user)->
         if err then handleError err
-        else group.fetchVms (err, vms)->
-          if err then handleError err
-          else vms.forEach (vm)->
-            vm.update {
-              $addToSet: users: { id: user.getId(), sudo: no }
-            }, handleError
+        else if group.slug is 'koding'
+          addVm member, user, sudo: yes
+        else
+          group.fetchVms (err, vms)->
+            if err then handleError err
+            else vms.forEach (vm)->
+              vm.update {
+                $addToSet: users: { id: user.getId(), sudo: no }
+              }, handleError
 
     JGroup.on 'MemberRemoved', ({group, member})->
       member.fetchUser (err, user)->
         if err then handleError err
+        else if group.slug is 'koding'
+          member.fetchVms (err, vms)->
+            if err then handleError err
+            else vms.forEach (vm)->
+              vm.update {
+                $set: { isEnabled: no, shouldDelete: yes }
+              }, handleError
         else
           # group.fetchVms (err, vms)->
           #   if err then handleError err

      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)->


    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.'
