Admin Remove User From Group

I'm writing my first plugin (for Elgg 1.7.6), to allow admins to add and remove users from groups. It adds a list of groups a user is a member of to the admin menu on the profile, and another list of groups the user isn't a member of. The idea is to click the group name to add or remove the user from that group.

It works for adding the user to a group, but it won't remove them. I get the error message "Could not leave group". I've used the following to create the link to add to a group:

$url = elgg_add_action_tokens_to_url("{$CONFIG->wwwroot}action/groups/join?group_guid=".$row->guid."&user_guid=".$userguid);

and this to remove:

$url = elgg_add_action_tokens_to_url("{$CONFIG->wwwroot}action/groups/leave?group_guid=".$row->guid."&user_guid=".$userguid);

This creates a link like:

http://localhost/network/action/groups/leave?group_guid=847&user_guid=1343&__elgg_ts=1295571921&__elgg_token=0cb85ffb1f61b8ede40ecc3b8d21d7e4

Can someone explain this, and suggest a way round it?