Your suggestion isn't equivalent because it always rewrites the nextToken, whereas the nextToken should only get rewritten when:

`while (result.keys.length > limit) {` and `if (nextToken) {`

That said, this never actually rewrites the nextToken on the `result` object so something is not quite right here. I'll try and expose an issue with a unit test and fix this up.