Merge "Add logic for calculating offsets during writing"