clarify and reimplement query.distinct