refactor, add query support