Updated the writeOutput() method