Improved checking for invalid tokens.
Merge branch 'test' into dev