Backport of small fixes from the buffers branch.