added precalculation of offset