Improved file validation