Is this code the same as ucp_groups? If it is (or at least similar enough), could this be moved into a function that could be shared between the two files?