Small refactor and finally testing that results are groupped correctly
for contained tables