putting in check to get proper loops