Fix interface for template polymorphism, cleaning up code in all typing algorithms.