The shift seems to be always the same, so I would do something like:
```
val offsetShift = currentTemplateOffset - templateRegions.head.getStart
for ... {
  tr.setStar(tr.getStart + offset)
  ...
}
```
instead of having a mutable variable.