Refactoring of query usage