use map instead of for loop