Fix stdout flush on exit