added for loop to inner function of map function