Extracted the determination of the filename.