parameterise state and merge print_escaped speedups