Added more file checks.
Minor optimizations.