changed the range in the outer loop