fixed error in buffer flushing