added support for nested loops, fixes B_6 test