This should be done outside the loop