added regex for templates and refactor
refaactor tests. minimal changes