refactored file validation