changing .each to for loops