refactor using for-each