Use setvbuf instead of repeated fflush