add function to write out to file