minimized the big iteration loop