Actually, there is a built-in Template swap function. It is much simpler to use that instead of writing our own.