Converting the write_output() function