using pattern matching to change file checking part