Moved token_* functions out