Fixed bug in dynamic template matcher