Use Math.max to make the offset calculation more concise.