Fix nested 2 loop coding errors