fix offset calculation