updated template parsing logic