refactoring loops into 'each' function