better escaping and error handling