 
   return owner
 
-setOwnerOfStack = (stack, newOwnerId, oldOwner) ->
+
+setOwnerOfStack = (stack, newOwner, oldOwner, group) ->
+
+  newOwnerId = newOwner.getId()
 
   stack.unuseStackTemplate (err) ->
     log 'Failed to mark as unused stack:', err  if err


  # Update machine ownership to the admin who kicked the member
  machine.addUsers {
    targets: [ user ], asOwner: yes, sudo: yes, group: group.slug
  }, (err) ->
    log 'Failed to change ownership of machine:', err  if err


        'config.oldOwner' : oldOwner
      }
    }, (err) ->
      if err
      then log 'Failed to change ownership of stack:', err
      else newOwner.sendNotification 'MachineListUpdated', { group }


updateStacks = ({ reason, stacks, oldOwner, requester, group }) ->

  if reason is 'kick'
    stacks.forEach (stack) ->
      setOwnerOfStack stack, requester, oldOwner, group
  else
    stacks.forEach (stack) ->
      stack.delete (err) ->
