Added a way to write out the final dataset.