This seems weird.  You are depending on data that hasn't been set yet?  Offset starts at 1, in which case this will be the one previously set on initialization but later won't this look into the future?  Possibly also triggering segfaults.