added some file checking