Nit: should be `offset - 1` in this line and the previous.