merging offsets and offsets.index determination in one sub-function