query parser refactored so it can be extended