This is probably dumb and doesn't matter :), but should this be `null` instead of `undefined` if we're at the end? (I would hope none of our code depends on that...)