fixed error in offset calculations