Refactor select and filter on queries.