Latest logic + comments. Calling escape() on TermComponentQuery objects is commented out.