Fix accessing data() on empty range.

Also back-port some tiny fixes.