Refactoring queries to be more flexible and support expressions such as aggregate functions.