Refactor AQueryWriter. Less DRY. More maintainable.