wrote preliminary version of template matcher