refactoring 'for-each'