Fixed bug in nested loops.