Bug fix---make interating through a directory a bit more robust