added stats, flush and shutdown