   return owner
 
 
-changeOwnershipOfMachine = (machine, newOwner) ->
+setOwnerOfMachine = (machine, { account, user }) ->
 
   # Move machine ownership to the admin who kicked the member
   machine.addUsers {
-    targets: [ newOwner ], asOwner: yes
+    targets: [ user ], asOwner: yes, sudo: yes
   }, (err) ->
-    log 'Failed to change ownership:', err  if err
+    log 'Failed to change ownership of machine:', err  if err
 
+updateMachineUsers = ({ machines, user, requester, reason }) ->
 
-updateMachineUsers = (machines, user, requester, reason) ->
+  return  unless reason is 'kick'
 
   machines.forEach (machine) ->
     # Check if the user is owner of the machine

        queue.next()

    ->
      updateMachineUsers memberMachines, memberJUser, requesterJUser, reason
      queue.next()

  ]

      log "Couldn't remove user from users:", err  if err

      # if not owner this machine we leave it to existing owner
      return  if not owner

      # otherwise we move the ownership of the machine to the requester
      setOwnerOfMachine machine, requester


module.exports = memberRemoved = ({ group, member, requester }) ->
