Fix for clearing items in a group element

This resolves an issue introduced in I02b933d.

Setting the element group to null must be inside a loop, so the logic was
basically shamefully bad.

Change-Id: I76bc17fdb375b18b17cfdb47961f0a00fa12b707