refactoring Query API