Hey, thanks for looking! Yes, that should be ok, though it would be easier to reason about a lot of this code if the functions were smaller.

One thing I don't like is that later on we reassign token with the result of calling a method on token. Not necessary to change as part of this fix, though I did find it confusing when initially reading it.