Refactor each-loop (exercise 1)