fix bug in offset computation