fix error in offset calculation