Refactoring of offset calculation