Changed for loop to use map instead