Oh, that's wrong. But I think it would actually be better to use a loop here and skip i forward, rather than checking keyframe.offset each iteration.