Added QueryRewriter class and some more functionality