Fix bug in offset replacement