Don't call flush() at a library level which isn't checking for errors