Fixed bug when removing intermediate files