Fix template switching issue