Adding better template extraction

Change-Id: I2cac186d307798eec22b769dbfa7e087720eaff1