Some refactoring and more query plugins