 
   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

      updateStacks {
        stacks   : memberStacks
        oldOwner : memberJUser.getAt 'username'
        requesterId, reason
      }
      next()


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