nested for loop fixed
merge