Added a bit more robustness to the file iterator.