Pretty print XML output, fix flushing problem