Changes to write_output to automate visualisation