Replacing silly for loop with an underscore function