Investigate the possibility of using iterative rather than recursive search of the query structures for comparison of patterns. There is likely to be a memory overhead, but it is possible that it may lead to better performance than having the function calls and ensuing initialisation.