added check for the existence of files