reorganized for loops