Fixed a bug where token length would increase infinitely.

Added a test.