Move test out of inner loop.