Grouping code logic, but I don't think I'm grouping on the correct thing?