Added file checking logic