adding token manager, standardize the code a little bit