token management code