save intermediate results into files

so that processing does not have to start from the beginning each time