nested loops converted