added error handling for missing states
Merge https://github.com/jhewlett/token.js