instead of doing this, I would loop through the questions right away and for each one add the topic that matches the product it has assigned to it.