Fixed that ugly while loop and flush compatibility.
Merge pull request #1 from Folis/master

Fixed that ugly while loop and flush compatibility.

Conflicts:
	halp

The conflict was lame and stuff. Had to merge much.