Fixes a bug in the offset calculation