Refactored for-each loops