complete template switching function