Fixes to TextFormat and some small optimizations in utilities.ts