Commented out the stuff about saving intermediate files, because it does not help much and just uses lots of memory