Made file checking more generic (slightly less efficient)