working template matcher