Refactored 2nd loop