Refactored for loop