Fix bug for table in table and re-used groups

This leads to a memory leak so we need to look into it again.