revised iteration loop