better flush and shutdown