To avoid problems where null token causes script to se $gettok(a.b..d.e,4,46)is 'e' instead of 'd', you can use placeholder of a character that will never appear in the string. Such as checking to see if you are storing a NULL token and storing $chr(3) instead. Then, when retrieving tokens, you use $remove(token,$chr(3)). It doesn't matter what you use in place of $chr(3), as long as it's something that should never appear in the string.

Or: return $iif(token == $chr(3),$null,token)