Fixed that ugly while loop and flush compatibility.