Corrected Distinct Query and updated tests