Added error handling, test & a bug fix for template name parsing