fixing bugs in buffer management