Improved file checking