Yea, I kinda agree. In refactoring all the response building I think this would change. For this particular case, having the if statement in here makes the function quite well contained. You can pass it any grouped data and it will do the right thing. If the if moves out of this function then more validation should be done inside.