fixed template switching logic