Less duplication in the loop

Signed-off-by: Gawain Lynch <gawain.lynch@gmail.com>