Fix bug in storing intermediate filenames