Fixed error in offset calculation