Escape backslashes only when necessary