Improving IOBuffer flush. Wait for buffer to empty. Use sleep mode.