Optimize code: Implement single-pass escaping