optimize groupJoinData to use a single loop