better mash function and fix for token side effects