Improve escaping and error conditions.