Refactoring and separating the query part from the filter