add flushing in TreePrinter