Fix various errors detected through Travis CI, and revert tokens.py changes