Improvements to exercise 23, with file output