Fixed writing of results in optimizer.