Fix bug with buffered queries