Added escaping tests and fixed bug in escaping code.