Fix escaping of single quote. Closes #307, updates tests.