Fix dereferencing data() on empty range.

Also back-port some tiny fixes.