Test refactoring.
Added support for distinct.