Adding recursive template detection

Change-Id: Ic574b98ce928c25ec590c5fdbc2b70a6d210157a