Added more logic for not downloading invalid files.