This should probably happen outside the while loop, it looks invariant