Improve testing for escaping and handling unicode
Fix escaping of single quotes when opening streams