Pull conditional out of inner loop.