refactoring of query object