can this check be outside the while loop?