Close #9 var declaration outside nested loops
Fix undeclared var