cleanup
make sure stdout is automatically flushed if stdout is redirected to file