added a function with nested loop. it worked.