Correct me if I am wrong but I feel like this is an issue of splitting a bill and settling?
If so, @Jesse was kind enough to create a really cool way of optimizing it, you can find the tutorial here.
It makes the whole process easier. Hope this helps, and that this is what you need…