Stop using fflush() everywhere and just turn off buffering for stdout/stderr. Should have done this a long time ago.