Fix escaping and URI encoding