Replaced underscore calls with for loop