undef error - WHILE loop terminated (> 1000 iterations)