Rearrange code to remove an analyser warning.

The block for adding attributes was only run under one condition. Is it
worth declaring it as a block?