added writing intermediate results