added nested for loops