Better file validity checks