lib: add buffer code (need to debug though)