Fix the calculation of offset