Handling string escaping more cleverly