Fixed bug with hanging flush() command