Fixed bug in the expansion of templates introduced in earlier version.