move fflush outside of mutex