modified version on tomita-tokens script