fix buffer impl, add tests