buffers: major cleanup and improvements