make the substrs destructive, simplification and minor speedup