Sorry, my previous comment was off by few lines, $i is actually not defined here, this is outside the loop.