Use sets of NodeIDs/Groups instead of lists.

Almost no effect on the code, but more correct semantically.