Flushing buffer to make sure everything is written