Sort and clean up the output file a bit.