fized some bugs, inserted api_fflush_helper