added nest foreach loop to make a key value pair