consolidate for loops