smalloc: many changes, to be squashed
buffer: rework, to be squashed