Stopped script trying to read non-files (e.g. directories)