Fixed bug for nested templates