globally replace characters when escaping, not just first; reduce repetitions in code (@119)