Fix writer selection.
Move closing of results file to correct location.
Fix UNICODE support in XML writer.