Refactored code and HTML escaping API