Fixed the errors and warnings in the nested loop
Fixed errors and warnings in the nested loop