added code to cleanup intermediate files