Add greedy templates, and fix ambiguity logic.