fixed some bugs, and made little progress in buffer.cpp