fix suffix typo, take io out of state
parameterise state and merge print_escaped speedups