wrote a bunch of subgroup code to run calculations