Fixed calculation of offset before actual data begins