used more appropriate flag to determine if sweeping
corrected if statement