refactor file checking