applying template design pattern to query decoder algorithm