Query refactor (for API usability)