Fix bracketing and quoting

Only remove backslashes when the string has been bracketed/quoted.
Make sure to escape backslashes when re-applying brackets/quotes.