extend functions to use RandomAccessRanges