fix buffer bugs and rewrite test for simple buffer