Moved fflush to prevent unnecessary flushing