Fixed a few bugs in the buffer code