smalloc: many changes, to be squashed