More fixes backported from the buffers branch.