refactored the code a lot, introducing the group mediate object