Also, it would be good to introduce optimizations from the previous version so the REDUCED and DISTINCT will work properly.